I have a table which looks something like this:
--------EXAMPLE---------------------------------------------------------
Cat1 Cat2 Value
a NULL 131
b e1 143
a e2 135
c NULL 136
a e1 132
a NULL 13
c e4 1
I want to select the row from above which has the highest value for various types in Cat1. So, my answer would look like the following:
--------EXAMPLE---------------------------------------------------------
Cat1 Cat2 Value
b e1 143
a e2 135
c NULL 136
I am using Microsoft SQL and I am looking for something efficient as I have about 40 million rows in my table that needs manipulation.
Thanks!!
You can use a
CTEwithDENSE_RANK:Use
Row_Numberinstead ofDense_Rankif you just want a single (arbitrary) record if there are multiple records with the same highest value.