Click here to Skip to main content
15,890,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
My Table Structure is Like as Follows

Hdr_Id Range1 Max_Range
1 10-7 10
2 22-3 22
3 10-6 10
3 5-1 5
4 10-7 10
4 7-4 7
5 7-6 7
5 5-4 5
6 10-7 10
7 25-18 25
7 10-3 10
8 5-3 5
9 20-5 20
10 15-5 15
10 5-3 5

Now I have to find Record With Maximum Range of Same Header Id like as follows

Hdr_Id Range1 Max_Range
1 10-7 10
2 22-3 22
3 10-6 10
4 10-7 10

pleas help.....
Posted

1 solution

SQL
SELECT * FROM
(
SELECT RANK() OVER (PARTITION BY Hdr_Id ORDER BY Max_Range DESC) AS 'Rank', *
FROM MYTABLENAME
) AS A WHERE RANK = 1
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900