sql多個count
發布時間: 2023-01-18 12:22:15
㈠ sqlserver怎麼實現同一個表中多個count查詢並且分組並且統計總數
可以有兩種解決方法,
所需工具: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
熱點內容