Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 draw problem

Author  Topic 

constantinos1987
Starting Member

25 Posts

Posted - 2008-11-29 : 12:47:15
i want to find the 3 customers with the maximum sales_amount. in case of draw i would like to project all of them

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-29 : 12:49:57
[code]select top 3 * with ties from your table order by sales_amount desc[/code]
Go to Top of Page

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2008-11-29 : 23:41:21
That should be
select top 3 with ties * 
from your table
order by sales_amount desc
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-30 : 01:34:55
or if sql 2000 use

select * from yourtable t
inner join
(select top 3 sales_amount
from yourtable
order by sales_amount desc) tmp
on tmp.sales_amount=t.sales_amount
Go to Top of Page

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2008-11-30 : 01:40:57
quote:
Originally posted by visakh16

or if sql 2000 use

select * from yourtable t
inner join
(select top 3 sales_amount
from yourtable
order by sales_amount desc) tmp
on tmp.sales_amount=t.sales_amount



TOP x WITH TIES is available in SQL Server 2000
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-30 : 01:46:08
quote:
Originally posted by snSQL

quote:
Originally posted by visakh16

or if sql 2000 use

select * from yourtable t
inner join
(select top 3 sales_amount
from yourtable
order by sales_amount desc) tmp
on tmp.sales_amount=t.sales_amount



TOP x WITH TIES is available in SQL Server 2000


yup it is
i thought its available only from 2005

Go to Top of Page
   

- Advertisement -