kingberrill of SQL
6/29/2017 - 8:46 PM

SUM()

SUM()

-To total up numeric columns use the SUM() function.
SELECT SUM(<numeric column) FROM <table>;
SELECT SUM(<numeric column) AS <alias> FROM <table>
                                       GROUP BY <another column>
                                       HAVING <alias> <operator> <value>;
                                       
                                       
-- retrieve customer who sent over 250           
SELECT SUM(cost) AS total_spend,  user_id FROM orders
  GROUP BY user_id
  HAVING total_spend > 250
  ORDER BY total_spend DESC