Oracle SQL在单列中计算不同值的实例-继续 [英] Oracle sql to count instances of different values in single column - continuation
本文介绍了Oracle SQL在单列中计算不同值的实例-继续的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我先前发布的问题的延续 链接在这里 Oracle sql以单个计数不同值的实例列
This is in continuation to an earlier question I had posted Here is the link Oracle sql to count instances of different values in single column
为进一步进行透视查询,我正在尝试做类似的事情
In further continuation to the pivot query, I am trying to do something like
对于( Count_status20为col20, Count_status30或Count_status40作为col30, Count_status50作为col50) 输入的内容与先前的问题相同.
for col in ( Count_status20 as col20, Count_status30 or Count_status40 as col30, Count_status50 as col50) The input remaning the same as earlier question.
基本上在这里,我试图将30或40中的状态汇总为一列.
Basically here I am trying to sum statuses in 30 or 40 as one column.
推荐答案
尝试如下:
select *
from
(
select tkey, status,
decode(status, 30, 30, 40, 30,status) as col
from tableB b
left join tableA a
on a.fkey = b.fkey
) src
pivot
(
count(status)
for col in ('20' as Count_Status20,
'30' as Count_Status3040,
'50' as Count_Status50)
) piv;
这里是小提琴
这篇关于Oracle SQL在单列中计算不同值的实例-继续的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文