Oracle/SQL Couting multiple colums grouped by a common column -
i'm yet oracle query. want do counting on multiple columns grouped common field. have half of done far. given following table
thing action -------------- t1 _a_ t1 _a_ t1 _b_ t2 _a_ t2 _b_
i have query
select thing, count(action) "a" <table> action = '_a_' group thing
which results in
thing ---------- t1 2 t2 1
what see though this
thing b -------------- t1 2 1 t2 1 1
but i'm not how that. ideas?
thanks!
select thing, count(case action when '_a_' 1 end) a, count(case action when '_b_' 1 end) b <table> group thing
or sum(case action when '_a_' 1 else 0 end)
if prefer
Comments
Post a Comment