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


Good job! Even though we already computed the final ratio in step 2, we typically also want to round the ratio to a given number of decimal places. To that end, we can use the ROUND(value, decimal_places) function. Take a look:

    WHEN ShippedDate IS NOT NULL
      THEN OrderID
  END) AS CountShipped,
  COUNT(OrderID) AS CountAll,
    WHEN ShippedDate IS NOT NULL
      THEN OrderID
  END) / CAST(COUNT(OrderID) AS float), 2) AS ShippedRatio
FROM Orders;

We surrounded the last column with the ROUND(..., 2) function invocation. Because the second argument is 2, we'll get the ratio rounded to two decimal places.


Modify the template code. Round the ratio from the DiscountedRatio column to three decimal places.

Stuck? Here's a hint!

Wrap your division with a call to ROUND(..., 3).