可以有两种解决方法, 所需工具:SQL 查询两个count的方法1: SELECT paperName , COUNT (1) AS 总题数 , sum (CASE WHEN statu = 1 THEN 1 ELSE 0 END) AS 审核题数FROM questionGROUP BY paperNme查询两个count的方法2: select s.总题数, s.审核题数, s.paperNamefrom (select COUNT(1) as 总题数, case when status = 1 then count(1) else 0 end as 审核题数, paperNamefrom question--where papername in (select distinct paperName from question), 这个条件可以不要了group by paperNme, stauts -- status也要作为分组字段,因为在case中有使用) s备注:两个都可以使用。
SELECT COUNT1+COUNT2 FROM (select A,count(*) COUNT1 from table_name where B='True' GROUP BY A) C, (select A,count(*) COUNT2 from table_name where B='False' OR B='false' GROUP BY A) D where C.A=D.A