1

我有一个查询如下。此查询应返回多行,但仅返回两行,因为某些行在状态表中没有连接行。任何人都可以帮助我修复此查询,以便即使状态表中没有连接行,它也会计算所有行。

SELECT count(h.h1_id)
FROM h1 h, owner o, ent e, status s
WHERE o.owner_id = h.owner_id AND e.enterprise_id = h.enterprise_id AND
h.herd_id=s.o_id AND s.o_type='H' AND h.code = 'QWE'
AND s.group_code!='123' AND s.status_code!='ABC'

谢谢!

4

1 回答 1

1
SELECT count(h.h1_id)
FROM h1 h
INNER JOIN owner o
ON o.owner_id = h.owner_id
INNER JOIN ent e
ON e.enterprise_id = h.enterprise_id
LEFT OUTER JOIN status s
ON h.herd_id=s.o_id 
where h.code = 'QWE'
AND ((s.o_type='H' AND s.group_code!='123' AND s.status_code!='ABC') OR (s.oid is null))
于 2013-06-24T13:43:28.533 回答