Great! Now that we know how to find the count of all customers and the count of those who've made a purchase, we can calculate the global lifetime conversion rate:
SELECT ROUND(COUNT(FirstOrderId) / CAST(COUNT(*) AS FLOAT), 2) AS ConversionRate
We simply divided the number of made-a-purchase customers by the total number of registered customers. Notice that we cast the denominator to a
FLOAT type using
CAST(COUNT(*) AS FLOAT). Both the numerator and the denominator are integers, so SQL Server would use integer division by default. The result would be incorrect, so we had to cast one of the values to force float division.
We also used the
ROUND(value, number) function, which rounds the given value to the given number of decimal places.