Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Multiple metrics for a single object
Metrics for two groups
Ratios and percentages
Global vs. specific metrics
13. Global vs. specific metrics – exercise
Summary

Instruction

Excellent! Let's do another exercise.

Exercise

For each country, find the percentage of revenue generated by orders shipped to it in 2018. Show three columns:

  1. ship_country.
  2. revenue – the total revenue generated by all orders shipped to that country in 2018.
  3. revenue_percentage – the percentage of that year's revenue generated by orders shipped to that country in 2018.

Round the percentage to two decimal places. Order the results in descending order by the revenue column.

Stuck? Here's a hint!

In the inner query, calculate the revenue in 2018. Use the result in the outer query.

Use the following formula to calculate the percentage:

ROUND(SUM(quantity * unit_price) / total_sales.sales_2018 * 100, 2) AS revenue_percentage