将来自同一表的单独查询组合为单独的列

时间:2018-01-19 10:04:33

标签: sql oracle union dbvisualizer

我有一个查询,我正在尝试组合但使用不同的列。具体情况如下:

  • 同桌
  • 不同的Where子句
  • Oracle DB
  • 参加DBVisualizer

这就是我想要做的事情:它运行但它没有加入两列。它们将被输出到DBVisualizer

中的单独结果选项卡中
    Select count (distinct CODE)   AS Comp_PCT
    from cons.GM
    Where POLICY='NR'
    And PCT is null

    UNION

    Select count (distinct CODE) AS Comp_DTY
    from cons.GM  
    Where POLICY='NR'
    And DTY is null

1 个答案:

答案 0 :(得分:0)

我不知道这个答案是正确的形式:

SELECT
  (Select count (distinct CODE)
    from cons.GM
    Where POLICY='NR'
    And PCT is null) AS Comp_PCT,
  (Select count (distinct CODE)
    from cons.GM  
    Where POLICY='NR'
    And DTY is null)  AS Comp_DTY