Instruction
Perfect! Now,we'll add a third column to our query:
SELECT
COUNT(CASE
WHEN ShippedDate IS NOT NULL
THEN OrderID
END) AS CountShipped,
COUNT(OrderID) AS CountAll,
COUNT(CASE
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).
Exercise
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.




