SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Using Top in select
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

oasis1
Starting Member

34 Posts

Posted - 10/02/2012 :  17:01:54  Show Profile  Reply with Quote
is there a way to use Top to find the top 10 for example for each year rather than just returning the top 10 over all? mahalo, Brew

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 10/02/2012 :  17:22:24  Show Profile  Reply with Quote
yep...but not using top. you can use below logic


SELECT
FROM
(
SELECT ROW_NUMBER() ORDER (PARTITION BY yearfield ORDER BY yoursortfield) AS seq,*
FROM table
)t
WHERE seq<=10


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000