我有以下表,Persons_Companies
,這顯示了這些人的個人和公司的已知,之間的關係:SQL簡單的查詢
PersonID | CompanyID
1 1
2 1
2 2
3 2
4 2
想象公司1 =「谷歌」和公司2 =「微軟」 ,我想知道查詢有以下結果:
PersonID | Microsoft | Google
1 0 1
2 1 1
3 1 0
4 1 0
直到這一刻我有類似的東西:
select PersonID,
case when CompanyID=1 then 1 else 0
end as Google,
case when EmpresaID=2 then 1 else 0
end as Microsoft
from Persons_Companies
我的問題是與兩個公司都知道的人,我無法想象這個查詢怎麼可能。
什麼是SQL查詢?
非常感謝。 最好的問候。 何塞 – Sosi 2010-03-22 15:14:46