如何将两个查询组合在一起以获得3列? BR_SURG_SLN_POS和BR_SURG_NSLN_POS总是为0-4,因此如果这两列可以合并为一列,因为它们的值相同。 我希望接下来的两列是计数(BR_SURG_SLN_POS)和计数(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
答案 0 :(得分: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
;