select 10 rows per day with order

前端 未结 9 548
感情败类
感情败类 2021-02-06 16:08

i have a db with records with date (timestamp) i need to select 10 records for each day (there are many more per day) and order them by few columns...

how should that qu

9条回答
  •  温柔的废话
    2021-02-06 16:51

    To select the top 10 records for each day ordered by days in SQL Server 2005

    select * from 
    (select *,ROW_NUMBER()
    OVER
    (PARTITION BY record.day order by record.day desc,record.score desc)
    as row from record) 
    as table1 where row < 11
    

    Now since your record table doesn´t have a day column as such, you need to use something like datepart(day, record.date) instead of record.day

    This should solve your problem

提交回复
热议问题