@场景
根据批次号统计不同状态的数量
表设计:
根据批次号结合status,查询总数量,失败数量、成功数量
SELECT COUNT(1) totalCount,
sum(CASE WHEN t.batch_no=1111 and t.`status` = 0 THEN 1 ELSE 0 END) succeedCount ,
sum(CASE WHEN t.batch_no=1111 and t.`status` = 1 THEN 1 ELSE 0 END) failCount
FROM
t_batch_logs t where batch_no=1111;
结果
查询结果: