Skip to content
Advertisement

how to select max of two columns and group it by station

I have a simple table like this

The output desired is like this

i wrote this code but for station=1 and num=200 return two rows

Advertisement

Answer

One possible approach is to use ROW_NUMBER() to number rows grouped by station and ordered by num and tim descending and then select the rows with number equal to 1.

Input:

Statement:

Output:

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement