我有一张桌子:
Id Date color
-------------------------
1 23/04/2013 red
2 23/04/2013 white
3 23/04/2013 yellow
4 23/04/2013 red
5 23/04/2013 orange
6 23/04/2013 blue
7 23/04/2013 yellow
8 23/04/2013 red
我按颜色分组,按总数和颜色排序:
Select top 5 color, count(color) as total from table where Date<=getdate() group by color order by total desc, color asc
所以直到这里,一切都好。
现在,我想要同样的,但不是按颜色订购。我想按总数排序,然后按日期排序。但我不想按日期分组。