How do you sum the results of a calculated column into one number in SQL?
SELECT
id, SUM(cost + r_cost) AS Revenue
FROM
revenue_table
WHERE
signup_date >= '2015-01-01'
GROUP BY
id
ORDER BY
Revenue DESC
LIMIT 20;
This query displays the revenue to date of the top 20 customers. How can I quickly do a total sum of the Revenue to get the total Revenue of the top 20 guys?
Group By id With Rollup, or you could wrap everything in a sub-query andSUMthe Revenue column.LIMITlooks like MySQL)