Weekly shipping report. Two things look wrong and I can't tell if they're the same thing.
The query:
SELECT o.warehouse,
COUNT(*) AS rows_seen,
COUNT(o.shipped_at) AS with_date,
COUNT(o.shipped_at) / COUNT(*) AS ship_ratio,
ROUND(100.0 * COUNT(o.shipped_at) / COUNT(*), 1) AS ship_pct,
SUM(l.qty) AS units
FROM orders o
JOIN order_lines l ON l.order_id = o.id
GROUP BY o.warehouse
ORDER BY o.warehouse;
Output:
fresno|4|3|0|75.0|9
reno|6|4|0|66.7|12
tulsa|3|1|0|33.3|9
ship_ratio is 0 for every warehouse. I think that's SQLite doing something with the division? Maybe.
But reno has 4 orders, and only 2 have a ship date. I counted by hand. The report says 66.7. A plain count of orders per warehouse gives reno 4, so the 6 in rows_seen confuses me too.
Is it the pending orders with the empty shipped_at? I haven't tried anything on that yet. Not sure where to even look first...