Oracle/SQL将多个列按公共列分组

Oracle/SQL将多个列按公共列分组,sql,oracle,count,group-by,Sql,Oracle,Count,Group By,我又回到了另一个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 但我想看到的是 THIN

我又回到了另一个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 B
--------------
T1    2   1
T2    1   1
但我不知道该怎么做。有什么想法吗

谢谢

select thing,
       count(case action when '_A_' then 1 end) as a,
       count(case action when '_B_' then 1 end) as b
from <table>
group by thing
或当“\u A\u”时的sumcase操作,如果愿意,则1或0结束

或当“\u A\u”时的sumcase操作,如果愿意,则1或0结束

select thing,
       count(case action when '_A_' then 1 end) as a,
       count(case action when '_B_' then 1 end) as b
from <table>
group by thing