SQL 怎么同时查询3个count
创建视图“分段统计”,显示为每门课程良好以上及良好以下的学生人数,具体形式如实验图2所示。表是score(学号,课程编号,成绩,学期)...
创建视图“分段统计”,显示为每门课程良好以上及良好以下的学生人数,具体形式如实验图2所示。表是score(学号,课程编号,成绩,学期)
展开
1个回答
展开全部
可以有两种解决方法。
方法1:
SELECT paperName
, COUNT (1) AS 总题数
, sum (CASE WHEN statu = 1 THEN 1 ELSE 0 END) AS 审核题数
FROM question
GROUP BY paperNme
方法2:
select s.总题数, s.审核题数, s.paperName
from (
select COUNT(1) as 总题数, case when status = 1 then count(1) else 0 end as 审核题数, paperName
from question
--where papername in (select distinct paperName from question), 这个条件可以不要了
group by paperNme, stauts -- status也要作为分组字段,因为在case中有使用
) s
方法1:
SELECT paperName
, COUNT (1) AS 总题数
, sum (CASE WHEN statu = 1 THEN 1 ELSE 0 END) AS 审核题数
FROM question
GROUP BY paperNme
方法2:
select s.总题数, s.审核题数, s.paperName
from (
select COUNT(1) as 总题数, case when status = 1 then count(1) else 0 end as 审核题数, paperName
from question
--where papername in (select distinct paperName from question), 这个条件可以不要了
group by paperNme, stauts -- status也要作为分组字段,因为在case中有使用
) s
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询