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 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) AS ShippedRatio
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 Server to use floating-point division. To do that, we cast one of the metrics to the float data type: CAST(COUNT(OrderID) AS float).


Add a third column to the template code: DiscountedRatio. 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 float) for floating-point division.