MYSQL - SUM of a column based on common value in other column

前端 未结 3 1966
日久生厌
日久生厌 2021-01-29 01:52

I\'m stuck on crafting a MySQL query to solve a problem. I\'m trying to iterate through a list of \"sales\" where I\'m trying to sort the Customer IDs listed by their total accu

相关标签:
3条回答
  • 2021-01-29 01:56

    You need to GROUP BY your customer id:

    SELECT CustomerID, SUM(PurchasePrice) AS PurchaseTotal
    FROM sales
    GROUP BY CustomerID;
    
    0 讨论(0)
  • 2021-01-29 01:58

    Select CustomerID, sum(PurchasePrice) as PurchaseTotal FROM sales GROUP BY CustomerID ORDER BY PurchaseTotal ASC;

    0 讨论(0)
  • 2021-01-29 02:01

    Just by having a little Google search, I managed to find a page doing exactly what you're doing (I think). I have tailored the query below to fit your circumstance.

    SELECT CustomerID, SUM(PurchasePrice) AS PurchaseTotal
    FROM sales
    GROUP BY CustomerID
    ORDER BY PurchaseTotal ASC
    

    Link to Page with Tutorial on SQL Groups

    0 讨论(0)
提交回复
热议问题