Using SUM in an SQL query

后端 未结 2 1689
无人及你
无人及你 2020-12-22 14:04

I\'m trying to do a query where it adds up the totals for the orders from each customer.

I have tried a few different ways but I am not sure the right way to do it.<

相关标签:
2条回答
  • 2020-12-22 14:49

    Sum and count can be used to get the result you want:

    select CustomerID, count(*) as Orders, ShipName, sum(Total) as Total
    from Table
    group by CustomerID, ShipName
    order by count(*) desc;
    
    0 讨论(0)
  • 2020-12-22 14:50
    select CustomerID, count(OrderID) Orders, ShipName, sum(Total) Total
    from Order_TAB
    group by CustomerID, ShipName
    
    0 讨论(0)
提交回复
热议问题