我有一张硬件表和事件表。每个硬件都有一个唯一标记,事件与标记绑定。
如何选择至少有一个事件列为未解决的所有硬件?
我不能只是做一个连接,因为如果一个硬件有多个未解决的问题,它会多次出现。
答案 0 :(得分:10)
select distinct(hardware_name)
from hardware,incidents
where hardware.id = incidents.hardware_id and incidents.resolved=0;
答案 1 :(得分:3)
这样的事情应该这样做:
Select A.HardwareID A.HadwareName, B.UnresolvedCount
From (Hardware A)
Inner Join
(
Select HardwareID, Count(1) As UnresolvedCount
From Incidents
Where Resolved = 0
Group By HardwareID
) As B On A.HardwareID = B.HardwareID
答案 2 :(得分:0)
这也可以起作用
SELECT hd.name, inc.issue, FROM hardware hd INNER JOIN inc ON hd.tag = inc.tag AND inc.issue = 'unresolved' group by hd.name