表中有几个可以筛选的字段:is_locked, is_finished, is_deleted,如果用一条sql语句同时统计这个表中的所有状态的项目的数量:
SELECT count(table.id) as total,
count(CASE table.is_finished WHEN 1 THEN 1 END) AS finished,
count(CASE table.is_locked WHEN 0 THEN 1 END ) AS unlocked,
count(CASE table.is_deleted WHEN 1 THEN 1 END ) AS deleted
FROM table;
查询结果:
total finished unlocked deleted
100 30 30 2