SQL group by day, show orders for each day

后端 未结 6 1593
梦毁少年i
梦毁少年i 2020-12-15 22:44

I have an SQL 2005 table, let\'s call it Orders, in the format:

OrderID, OrderDate,  OrderAmount
1,       25/11/2008, 10
2,       25/11/2008, 2
3,       30/1         


        
6条回答
  •  余生分开走
    2020-12-15 23:29

    Depending on how SQL Server handles temporary tables, you can more or less easily arrange to create a temporary table and populate it with the 7 (or was that 8?) dates you are interested in. You can then use that as your tally table. There isn't a cleaner way that I know of; you can only select data that exists in a table or that can be derived from data that exists in a table or set of tables. If there are dates not represented in the Orders table, you can't select those dates from the Orders table.

提交回复
热议问题