주간 배송 리포트예요. 이상한 게 두 가지 있는데 같은 문제인지 모르겠어요.
쿼리예요:
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;
출력:
fresno|4|3|0|75.0|9
reno|6|4|0|66.7|12
tulsa|3|1|0|33.3|9
ship_ratio가 모든 warehouse에서 0이에요. SQLite가 나눗셈에서 뭔가 하는 것 같은데요? 아마도요.
그런데 reno는 주문이 4개고 그중 2개만 배송일이 있어요. 손으로 세어 봤어요. 리포트에는 66.7이라고 나와요. warehouse별로 주문 수만 단순 count하면 reno가 4라서, rows_seen의 6도 이해가 안 돼요.
shipped_at이 비어 있는 보류 주문 때문일까요? 아직 그쪽은 아무것도 안 해 봤어요. 어디부터 봐야 할지도 잘 모르겠어요...
영어에서 번역·원문 보기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...