Skip to content
/Chapter 10 · Practical Analytics Patterns
Lesson 10.2·garden_shop
Lesson 10.2

Percentages and Rates in SQL

Rates are everywhere: conversion, completion, usage. Each is a numerator over a denominator, scaled to a percentage.

A rate is just a fraction with a story: how many of the whole match some condition. The shape is always numerator ÷ denominator × 100. The numerator is a conditional count; the denominator is the total.

One thing to watch in some databases: dividing two integers can throw away the fraction (so 17 / 24 becomes 0). Writing the multiplier as 100.0 keeps the pattern portable, and round() tidies the result.

Pattern
select round(100.0 * converted / total, 1) as conversion_pct
from funnel
Schema · Garden ShopTable · orders6 columns · 24 rows
Table · orders

One row per order. Unshipped orders have a null shipped_date.

6 columns · 24 rows
order_id intcustomer_id intorder_date dateshipped_date datestatus textcoupon_code text
Your task

What share of orders have shipped? Extend the starter so it also returnspct_shipped: the percentage of all orders whose status is'shipped', rounded to one decimal place.

SQL Workbench
query.sqlgarden_shop · SQL engine loading
⌘↵ to run
·
Expected answer
  • Columns: total_orders, shipped_orders, pct_shipped.
  • Rows: 1 summary row.
  • 17 of 24 orders shipped, so pct_shipped is 70.8.