获取所有结果的查询(包括条件不满足时)

时间:2017-11-22 17:57:38

标签: oracle

我试图通过这些查询来计算。我希望它显示我所有的名字主持人(虽然计数是0)但是有了这些查询,。如果没有where条款我就没有任何问题,但是在哪里,条款并没有告诉我姓名主持人。请问你能帮我吗?

表格示例:

nodes         
=======
nameHost        nodeid
---------       -------
a               a
b               b
b               f
e               e
g               g


jobsDefinition
================
node_id        job_name      app
----------     -----------   ---
a               fruit        one
b               apple        two
c               iron         three
a               banana       four
f               orange       four
g               gold         five

输出结果为:

a 2 (fruit,banana)
b 2 (apple,orange)
e 0
***g 0 --> **this record not show me*****

这是我的代码

  SELECT n.namehost,
         COUNT (jd.node_id) AS Cnt,
         LISTAGG (jd.job_name, ',') WITHIN GROUP (ORDER BY 1) JB_NM
    FROM nodes n 
    LEFT JOIN jobdef jd 
    ON n.nodeid = jd.node_id
--sentence where
WHERE APP NOT LIKE 'five' 
GROUP BY n.namehost
ORDER BY namehost;

谢谢,对不起我的英文!

1 个答案:

答案 0 :(得分:2)

使用ON子句中的条件而不是where

  SELECT n.namehost,
         COUNT (jd.node_id) AS Cnt,
         LISTAGG (jd.job_name, ',') WITHIN GROUP (ORDER BY 1) JB_NM
    FROM nodes n 
    LEFT JOIN jobdef jd 
    ON n.nodeid = jd.node_id
AND APP NOT LIKE 'five' 
GROUP BY n.namehost
ORDER BY namehost;