;with MyRank (col1)as( select 5 union all select 4 union all select 3 union all select 2 union all select 1 union all select 1 union all select 1)select col1, MAX(RowNum) as MaxRowNumfrom( select col1, ROW_NUMBER() over (order by col1 desc) as RowNum from MyRank) x group by col1having Max(RowNum) <= 5order by col1 desc
;with MyRank (col1)as( select 5 union all select 4 union all select 3 union all select 2 union all select 1 union all select 1 union all select 1), MaxRank as( select col1, ROW_NUMBER() over (order by col1 desc) as RowNum from MyRank)select col1, MAX(RowNum) as MaxRowNumfrom MaxRankgroup by col1having Max(RowNum) <= 5order by col1 desc
;with MyRank (col1)as( select 5 union all select 4 union all select 3 union all select 2 union all select 1 union all select 1 union all select 1)SELECT TOP 5 col1FROM MyRankGROUP BY col1HAVING COUNT(*) = 1ORDER BY col1
;with MyRank (col1)as( select 6 union all select 5 union all select 4 union all select 3 union all select 2 union all select 2 union all select 1), MyRank2 as(SELECT TOP 5 col1, COUNT(*) AS RCountFROM MyRankGROUP BY col1)SELECT col1FROM MyRank2WHERE RCount = 1
;with MyRank (col1)as( select 6 union all select 5 union all select 4 union all select 3 union all select 2 union all select 2 union all select 1), MyRank2 as( SELECT TOP 5 col1, COUNT(*) AS RCount FROM MyRank GROUP BY col1 order by col1 desc --Need this order by to ensure which top 5)SELECT col1FROM MyRank2WHERE RCount = 1
;with MyRank (col1)as( select 6 union all select 5 union all select 5 union all select 4 union all select 3 union all select 2 union all select 1), MyRank2 as( SELECT TOP 5 col1, COUNT(*) AS RCount FROM MyRank GROUP BY col1 order by col1 desc --Need this order by to ensure which top 5)SELECT col1FROM MyRank2WHERE RCount = 1