我有一個表tblPersonaldata
和tblStudentsadmitted
集團通過不顯示所有行
tblPersonalData
UID Name Gender
------------------------
E1 xyz M
E2 pqr M
E3 mno M
tblStudentsadmitted
UID Status Stage
----------------------
E1 Y 1
E2 Y 2
E3 Y 1
現在我想是這樣的數據:
Gender Stage1 Stage2
M 2 1
但在這種情況下,我沒有得到的數據女性性別。我想對女性性別的數據,即使它是空
我已經試過這樣:
select
case
when gender='M' then 'Male'
when gender='F' then 'Female'
end as Gender,
sum(case when Stage=1 then 1 else 0) end as Stage1,
sum(case when Stage=2 then 1 else 0) end as Stage2
from tblPersonaldata A inner join
tblStudentsadmitted B on A.UID=B.UID
where B.Status='Y'
group by Gender
您的樣本表是否包含所有的信息? 因爲你沒有任何女性數據? – CathalMF 2013-03-12 11:41:03