Oracle/SQL 计算按公共列分组的多个列
我带着另一个 Oracle 查询回来了。我想要做的是对按公共字段分组的多个列进行计数。到目前为止我已经完成了一半。因此,给出下表,
THING ACTION
--------------
T1 _A_
T1 _A_
T1 _B_
T2 _A_
T2 _B_
我有这个查询
select THING,
count(ACTION) as "A"
from <table>
where ACTION = '_A_'
group by THING
,结果是
THING A
----------
T1 2
T2 1
我想看到的是这个,
THING A B
--------------
T1 2 1
T2 1 1
但我不确定如何做到这一点。有什么想法吗?
谢谢!
I'm back with yet another Oracle query. What I want to do is do counting on multiple columns grouped by a common field. I have half of this done so far. So given the following table
THING ACTION
--------------
T1 _A_
T1 _A_
T1 _B_
T2 _A_
T2 _B_
I have this query
select THING,
count(ACTION) as "A"
from <table>
where ACTION = '_A_'
group by THING
Which results in
THING A
----------
T1 2
T2 1
What I would like to see though is this
THING A B
--------------
T1 2 1
T2 1 1
But I'm not certain how to do that. Any ideas?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
或
sum(case action when '_A_' then 1 else 0 end)
如果您愿意or
sum(case action when '_A_' then 1 else 0 end)
if you prefer