I have a table with three columns
UserID, Count, Date
I’d like to be able to select the userid with the highest count for each date.
I’ve tried a few different variations of queries with inline select statements but none have worked 100%, and I’m not too fond of having a select with three inline selects.
Is doing inline selects the only way to go without using temp tables? Whats the best way to tackle this?
If [Date] is in fact a [Date] column with no time component:
If
[Date]is aDATETIMEcolumn with a time component, then:If you want to pick a specific row in the event of a tie, you can add a tie-breaker to the
ORDER BYwithin the over. If you want to include multiple rows in the case of ties, you can try changingROW_NUMBER()toDENSE_RANK().