我想根據經理名稱分組的program_code
字段對活躍參與者進行計數。但是我也希望在同一個查詢中需要滿足三個條件的其他內容。具有多個條件的案例陳述
select manager_name,
sum (case program_code when 'F' then 1 else 0 end) as F,
sum (case program_code
when 'FS' then 1
else 0
end)
from table1
where status='AC'
group by manager_name
但我想誰擁有possible_ind='Y' AND date_attended is not null AND status_cd='P'
我不能把在一個case
聲明與所有這些條件的所有參與者的第三計。有沒有辦法我可以做到這一點?它是否需要成爲select
子句中的子查詢?我用select
子句中的子查詢對它進行了嘗試,但它沒有按manager_name
對它進行分組。
select manager_name,
sum (program_code when 'F' then 1 else 0 end) as F,
sum (case program_code
when 'FS' then 1
else 0 end),
(select count(*)
from table1
where possible_ind='Y'
and date_attended is not null
and status_cd='P') as NEW
from table1
where status='AC'
group by manager_name
'status'和'status_cd'是兩個不同的列嗎? – peterm