Select Top n from multiple date values

Hello,

I have the following format:
Date,Equity,Systemident

I have multiple entries for the same date. Key will be systemident.
How can I select the top n value for a certain date interval?
So on each day I need the top n value for Equity.
For example top 5
On each day I need to have the top 5 equity.

Do I need a procedure or can it be a query?
SchuttendAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dportasCommented:
I will assume that "Date" is a DATE type column. Hopefully "Date" isn't the actual name you'll use for the column.

SELECT [Date], Equity
FROM
 (SELECT [Date], Equity,
  RANK() OVER (PARTITION BY [Date] ORDER BY Equity) rnk
  FROM tbl) t
WHERE rnk <= 5;

Try it with both RANK() and DENSE_RANK() and decide which one meets your requirements.
0
dportasCommented:
Or:

SELECT [Date], Equity
FROM
 (SELECT [Date], Equity,
  RANK() OVER (PARTITION BY [Date] ORDER BY Equity DESC) rnk
  FROM tbl) t
WHERE rnk <= 5;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SchuttendAuthor Commented:
Hi,

Almost getting there. It's need to be in the correct [Date] order. Now the results of jump up and down with dates. Like:
01/01/2000 -- result
01/05/2003 -- results
01/1/2001 - results

Maybe something with Group by ??
0
dportasCommented:
Just add ORDER BY [Date]
0
SchuttendAuthor Commented:
Thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.