Top 10 rows for each date

Database

Top 10 rows for each date

I need to generate a report for top 10 rows for each date in a table. I can write a statment for each date but can anyone help with writitng it in single query;

select top * from Table where date ='2014-01-01';
select top * from Table where date ='2014-02-01';
select top * from Table where date ='2014-03-01';

Looking for any help.

Br,

FK

Tags (1)
3 REPLIES
Junior Supporter

Re: Top 10 rows for each date

Hi.

If you need TOP only for SAMPLING (whithout ORDER BY) you could try stratified sampling.

SELECT *

  FROM TheTable

SAMPLE WHEN TheDate = '2014-01-01' THEN 10

            WHEN TheDate = '2014-2-01' THEN 10

...

END;

HTH

Cheers.

Carlos.

Enthusiast

Re: Top 10 rows for each date

Select * FROM Table Qualify Row_number()Over( partition by date order by column) between 1 and 10;

I think this should work..

Re: Top 10 rows for each date

Thanks Mani. It works. :)