SQL derived value by a set of Row

120 views Asked by At

Hi my table looks like this

1

Combination of Rows with same S id is termed as a family. Output should have a Calculated Tier code based on below derivation

Output put should be Output

First time i am using Stackoverflow. I need a query in db2 and I can use the output as a report.

1

There are 1 answers

4
Popeye On

You need windows function as follows:

Select t.*,
       Concat('Tier ', count(*) over (partition by s_id) ) as tier
  From your_table t