【问题标题】:Combining counts and merge column PL/SQL合并计数和合并列 PL/SQL
【发布时间】:2017-09-21 14:24:40
【问题描述】:

如何将这两个查询组合在一起以获得 3 列结果? BR_SURG_SLN_POS 和 BR_SURG_NSLN_POS 始终为 0-4,因此如果这两列可以合并为一列,因为它们的值相同。 我希望接下来的两列是 count(BR_SURG_SLN_POS) 和 count(BR_SURG_NSLN_POS)。我尝试使用 concat 合并两列,但这不是我想要的结果。

select 
br_surg_SLN_POS,
count(BR_SURG_SLN_POS)<BR>
from BR_SURGERY<BR>
where BR_SURG_SLN_POS between 0 and 4<BR>
group by 
BR_SURG_SLN_POS<BR>
order by 
BR_SURG_SLN_POS

select 
br_surg_NSLN_POS,
count(BR_SURG_NSLN_POS)<BR>
from BR_SURGERY<BR>
where BR_SURG_NSLN_POS between 0 and 4<BR>
group by 
BR_SURG_NSLN_POS<BR>
order by 
BR_SURG_NSLN_POS

与此类似:

【问题讨论】:

    标签: sql oracle merge count


    【解决方案1】:

    试试这个

    select t1.sln_value, t1.sln_cnt , t2.nsln_cnt from
         (select 
             br_surg_SLN_POS sln_value,
            count(BR_SURG_SLN_POS) sln_cnt
         from BR_SURGERY
          where BR_SURG_SLN_POS between 0 and 4<BR>
            group by 
               BR_SURG_SLN_POS) t1,
        (select 
               br_surg_NSLN_POS nsln_value,
              count(BR_SURG_NSLN_POS) nsln_cnt
             from BR_SURGERY
            where BR_SURG_NSLN_POS between 0 and 4
               group by 
                BR_SURG_NSLN_POS ) t2
                 where t1.sln_value = t2.nsln_value
               ;
    

    【讨论】:

    • 感谢帕万拉瓦特!我看到您如何命名列并加入我需要合并的列。非常好,非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-22
    • 2012-12-17
    • 1970-01-01
    相关资源
    最近更新 更多