mysql - Count specific values in column -


i'm trying count number of times multiple words appears in column named sg_event run each 1 separately. know how can combine 1 query.

select count(*) metrics sg_event = 'open';  select count(*) metrics sg_event = 'delivered';  select count(*) metrics sg_event = 'click'; 

my desired outcome follows,

open_count, delivered_count, click_count

you can use conditional sum this

select sum( case when sg_event = 'open' 1 else 0 end ) `open_count`, sum( case when sg_event = 'delivered' 1 else 0 end ) `delivered_count`, sum( case when sg_event = 'click' 1 else 0 end ) `click_count` metrics 

Comments

Popular posts from this blog

php - Admin SDK -- get information about the group -

dns - How To Use Custom Nameserver On Free Cloudflare? -

Python Error - TypeError: input expected at most 1 arguments, got 3 -