Data Browser - Viewing Site  Sector 23 Code Bank Logged in as:  Guest  




           


SQL Server Rank/Partition
How to partition sql results so that you get the min/max record along with its data.
(This can also be accomplished by using an Exists clause).

Select * from
(
Select a.GroupId, a.OtherField, a.Date1, a.Date2,
Rank() over (Partition by a.GroupId ORDER BY a.Date1, a.Date2) as Rank
from Tbl a
) summary
WHERE Rank = 1

Created By: amos 11/13/2012 1:01:53 PM
Updated: 1/18/2019 10:46:55 AM