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
7. Calculating ratios – step 2
Global vs. specific metrics


Perfect! Now,we'll add a third column to our query:

    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) / CAST(COUNT(order_id) AS decimal) AS shipped_ratio
FROM orders;

In the third column, we calculate the ratio by dividing the expression from the first column by the expression from the second column. However, both of these values are integers, so we need to force SQL to use floating-point division. To do that, we cast one of the metrics to the decimal data type: CAST(COUNT(order_id) AS decimal).


Add a third column to the template code: discounted_ratio. It should contain the ratio of discounted line items (from column 1) to all line items (from column 2).

Stuck? Here's a hint!

Remember to use CAST(... AS decimal) for floating-point division.