sql - Decode function for MySQL -
i've below sql:
select date_format(date_created, '%y-%m-%d') date_ , if(status=1,'success','failed') processed_status ,count(1) x date_format(date_created, '%y-%m-%d') between '2011-01-01' , '2015-06-04' group date_format(date_created, '%y-%m-%d') , status order date_format(date_created, '%y-%m-%d') desc;
actually format shown below
date_ processed_status count(1) 2015-05-15 failed 1 2015-05-13 failed 691 2015-05-13 success 68 2012-05-19 failed 346 2012-05-19 success 28 2012-05-18 failed 184 2012-05-18 success 18 2012-05-17 failed 176 2012-05-17 success 9 2012-05-16 failed 425 2012-05-16 success 49 2012-03-13 failed 1 2012-02-23 success 193
but need format:
date_ failed success
and inside on data shown date , count of failed , success.
usually on oracle, use decode function this, don't know mysql. please :)
use conditional aggregation:
select date_format(date_created, '%y-%m-%d') date_, sum(status = 1) success, sum(status <> 1 or status null) failed x date_format(date_created, '%y-%m-%d') between '2011-01-01' , '2015-06-04' group date_format(date_created, '%y-%m-%d') order date_format(date_created, '%y-%m-%d') desc;
Comments
Post a Comment