SQL group by day, show orders for each day

后端 未结 6 1574
梦毁少年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:26

    If you want to see value zero than put the following query:

    select count(*), sum(OrderAmount)
    from Orders
    where OrderDate>getdate()-7
      and sum(OrderAmount) > 0 or sum(OrderAmount) = 0
    group by datepart(day,OrderDate)
    

提交回复
热议问题