Calculate each customer's share of total revenue.
Calculate each customer's share of total revenue. Predict the output before running the example.
SELECT customer_id,SUM(amount) AS revenue,ROUND(100.0*SUM(amount)/(SELECT SUM(amount) FROM orders),1) AS revenue_pct FROM orders GROUP BY customer_id ORDER BY revenue DESC;
What does today's SQL feature do, and when would you use it?
Use 100.0 to avoid integer division.
Run the example, then modify one clause and predict how the result changes.
Use 100.0 to avoid integer division.