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
Actually it´s more like this, I had misplaced the order by for the date.
Here we assume there is a datetime field in the Records table and a score field to rank records.
SELECT *
FROM (SELECT *, ROW_NUMBER() OVER (PARTITION BY datepart(year, Record.date), datepart(month, Record.date), datepart(day, Record.date)
ORDER BY Record.score desc) AS row
FROM Record ) AS table1
WHERE row < 11
ORDER BY datepart(year, Record.date) desc, datepart(month, Record.date) desc, datepart(day, Record.date) desc