当我选择数据时,仅显示前lot
个数据。但我需要所有lot
数据。
这是我的查询:
SELECT lot,
(select count(pass) FROM pass_fail_result where pass=0) toatl_fail,
(select count(pass) FROM pass_fail_result where pass=1) toatl_pass FROM pass_fail_result group by lot;
答案 0 :(得分:0)
最简单的方法是通过条件聚合,我们计算或求和以失败或通过记录为目标的CASE
表达式:
SELECT
lot,
COUNT(CASE WHEN pass = 0 THEN 1 END) AS toatl_fail,
COUNT(CASE WHEN pass = 1 THEN 1 END) AS toatl_pass
FROM pass_fail_result
GROUP BY
lot;