我有兩個非常相似的SQL語句加入2 SQL選擇
select instrumentuniqueid, count(levelid) as errors
from dbo.testevent
join dbo.test
on dbo.test.id = dbo.testevent.testid where dbo.test.runid = 20962 and dbo.testevent.levelid = 1
group by instrumentuniqueid
select instrumentuniqueid, count(levelid) as warnings
from dbo.testevent
join dbo.test
on dbo.test.id = dbo.testevent.testid where runid = 20962 and levelid = 2
group by instrumentuniqueid
第一個產生instrumentuniqueid的列(聚集),把計數 第二個產生聚集instrumentuniqueid的列與不同的計數。
我如何加入他們在一起,這樣的決賽桌的樣子:
Instrumentuniqueid |錯誤|警告
將差異從WHERE子句移到COUNT中的CASE中。 – jarlh
與論壇網站不同,我們不使用「謝謝」或「任何幫助表示讚賞」,或在[so]上簽名。請參閱「[應該'嗨','謝謝',標語和致敬從帖子中刪除?](http://meta.stackexchange.com/questions/2950/should-hi-thanks-taglines-and-salutations-be - 刪除 - 從帖子)。順便說一句,這是「預先感謝」,而不是「感謝先進」。 –