Sample Header Ad - 728x90

How to narrow down records in SQL based on conditions

2 votes
1 answer
338 views
Customer Rank Joining_date salary A 2 2017-10-12 500 A 1 2017-10-10 800 A 1 2017-10-20 400 B 2 2017-05-20 200 B 2 2017-05-15 100 c 3 2017-06-10 600 c 4 2017-06-05 600 Logic: For a given customer if the Rank is 1 ,then retain all those records with rank 1 and drop rest if customer has records with different rank ,select the record based on latest rank (order by rank desc) and drop the other if the customer has records with same rank (other than 1),then select the record based on the lowest salary (order by salary asc)** Expected result Customer Rank Joining_date salary A 1 2017-10-10 800 A 1 2017-10-20 400 B 2 2017-05-15 100 c 4 2017-06-05 600
Asked by user8545255 (123 rep)
Aug 15, 2018, 11:35 PM
Last activity: Aug 17, 2018, 09:21 AM