On January 21th at 14:15 UTC , progression through exercises will be unavailable for 10 minutes due to a planned maintenance break.
Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Multiple metrics for a single object
Metrics for two groups
Ratios and percentages
9. Calculating percentages – step 4
Global vs. specific metrics


Great work! We originally wanted to see a percentage, so let's modify our query a little bit to calculate a percentage instead of a ratio. Here's step 4:

    WHEN shipped_date IS NOT NULL
      THEN order_id
  END) AS count_shipped,
  COUNT(order_id) AS count_all,
    WHEN shipped_date IS NOT NULL
      THEN order_id
  END) / COUNT(order_id)::decimal * 100, 2) AS shipped_ratio
FROM orders;

Note that we multiply the result of the division inside the ROUND() function by 100 to get a percentage instead of a ratio.


What is the percentage of discontinued items at Northwind? Show three columns: count_discontinued, count_all, and percentage_discontinued. Round the last column to two decimal places.

Stuck? Here's a hint!

Use the discontinued column from the products table. Remember to cast the denominator to decimal and to multiply the result by 100 to get a percentage.