每周发货报表。有两处看起来不对,我分不清是不是同一个问题。
查询如下。
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 在每个仓库都是 0。我猜是 SQLite 在除法上做了什么?也许吧。
可是 reno 有 4 个订单,只有 2 个有发货日期,我手数的。报表里却是 66.7。直接按仓库数订单的话 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...