使用此查詢我試着總結兩個SUM函數的結果:如何SUM結果兩個SUM SQL?
select
DAY(created_at) AS day,
SUM(if(status = '1', 1, 0)) AS result,
SUM(if(status = '2', 1, 0)) AS noresult,
SUM(result + noresult)
from `clients` where `doctor_id` = 2 and MONTH(created_at) = MONTH(CURRENT_TIMESTAMP) group by `day`
我嘗試這樣做,在這條線:
SUM(result + noresult)
你爲什麼不環繞另一個查詢查詢做SUM(結果+ noresult) –
使用'SUM(IF(狀態= '1',1,0))+ SUM(IF(狀態= '2',1,0))'而不是別名。 –