【问题标题】:Combining separate queries from the same table as separate columns将来自同一表的单独查询组合为单独的列
【发布时间】:2018-01-19 10:04:32
【问题描述】:

我有一个查询,我尝试将其与不同的列组合。具体如下:

  • 同一张表
  • 不同的 Where 子句
  • Oracle 数据库
  • 在 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

【问题讨论】:

  • 我不知道 DBVisualizer,但是 - 尝试删除 UNION 周围的空行。
  • 您为什么认为UNION 会“加入”这些列?请Edit您的问题并添加一些sample data 和基于该数据的预期输出。 Formatted textno screen shotsedit 您的问题 - 请不要在 cmets 中提供邮政编码或其他信息。

标签: sql oracle union dbvisualizer


【解决方案1】:

我不知道这个答案是否正确:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-03-12
    • 1970-01-01
    • 2013-04-28
    • 1970-01-01
    • 2014-06-08
    • 2019-02-05
    相关资源
    最近更新 更多