方法一、
復制代碼 代碼如下:
SELECT SUM(正確數)+SUM(錯誤數) AS 總記錄數,SUM(正確數),SUM(錯誤數)
FROM (
SELECT COUNT(1) 正確數,0 錯誤數
FROM TB
WHERE STATUS=1
UNION ALL
SELECT 0 正確數,COUNT(1) 錯誤數
FROM TB
WHERE STATUS=0) a
方法二、
復制代碼 代碼如下:select count(1)總記錄數,sum(case when status=1 then 1 else 0 end)正確數,sum(case when status=0 then 1 else 0 end) 錯誤數 from T