I have a table called trx
trx_year trx_month Product number_of_trx
2018 4 A 100
2018 5 A 300
2018 3 A 500
2018 1 A 200
2018 2 A 150
2018 5 B 400
2018 2 B 200
2018 1 B 350
I want the result:
Product with the number of trx that order by month asc
I have a query like this:
select product,GROUP_CONCAT(number_of_trx order by trx_month)
from trx
where trx_year=2018
group by product
The Result of that query:
Product Data
A 200,150,500,100,300
B 350,200,400
But, I want Result like this: (that the null value of the month replaced by 0)
Product Data
A 200,150,500,100,300
B 350,200,0,0,400
I already try ifnull()
and coalesce()
like this: (but the result is same as before)
select product,GROUP_CONCAT(ifnull(number_of_trx,0) order by trx_month)
from trx
where trx_year=2018
group by product;
select product,GROUP_CONCAT(coalesce(number_of_trx,0) order by trx_month)
from trx
where trx_year=2018
group by product;
maybe you can help me, please check http://sqlfiddle.com/#!9/f1ed4/3