/* ------------------------ My Meta Content Here SEO ------------------------ */

Pages

Main Menu




Wednesday, June 18, 2014

Using Top n, WITH TIES, and PERCENT in sql server


DECLARE @TEST TABLE(
ID int, Amount int)
INSERT INTO @TEST VALUES
(1,10),(2,30),(3,60),
(4,50),(5,50),(6,70),
(7,20),(8,70),(9,70),
(10,44),(11,80),(12,90)

select * from @TEST

select Top 3 ID, Amount from @TEST ORDER BY Amount desc

select Top 3 With TIES ID, Amount from @TEST ORDER BY Amount desc

select Top 3 PERCENT ID, Amount from @TEST ORDER BY Amount desc

No comments:

Post a Comment

Recent Posts

My Blog List