The SQL Top Command
hello,
say have table listing state\counties in world country in. to top 10 counties country.
i can the top 10 counties, cannot go step country, like:
for usa:
coutries 1 - 10
for uk:
coutries 1 - 10
for spain
coutries 1 - 10
thanks help, tyrone
if you're using sql 2005 , up, it's simple problem using row_number() function partition, e.g.
;with cte as (select country, county, row_number() over (partition by country order by county) as rn from listofcountriescounties) select * from cte where rn<=10 order by country, rn
for every expert, there equal , opposite expert. - becker's law
my blog
SQL Server > Getting started with SQL Server
Comments
Post a Comment