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(first_order_id) / CAST(COUNT(*) AS float), 2) AS conversion_rate
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 the database 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.