Informix外部联接

时间:2013-06-24 13:40:10

标签: sql

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

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'

谢谢!

1 个答案:

答案 0 :(得分: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))