我有两个非常相似的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 - 删除 - 从帖子)。顺便说一句,这是“预先感谢”,而不是“感谢先进”。 –