SQL问题 - 外连接似乎无法正常工作

时间:2011-07-26 16:31:22

标签: sql-server

  

可能重复:
  sql question - outer join seems not to work

通过以下查询,我得到50个结果:

SELECT count(*) AS total_num, TS_NAME
FROM TS_COMPANIES RIGHT OUTER JOIN TTS_INCIDENTS
ON (TS_COMPANIES.TS_ID=TTS_INCIDENTS.TS_COMPANYID AND TS_LEVEL2TECH=0)
WHERE TS_ACTIVEINACTIVE = 0 AND (TS_INCIDENTTYPE=10 OR TS_INCIDENTTYPE=11) 
GROUP BY TS_NAME
ORDER BY  TS_NAME

但是如果从ON子句中删除TS_LEVEL2TECH = 0,我会得到70个结果。

如何过滤TS_LEVEL2TECH = 0并仍然获得70个结果?

1 个答案:

答案 0 :(得分:0)

这是不明确的,因为你并没有真正说TS_LEVEL2TECH来自哪里,TS_COMPANIES或TTS_INCIDENTS,一些表别名在这里真的有用。 (同样适用于TS_NAME等)