Here's my query:
mysql>
select DATE_FORMAT(STR_TO_DATE(items.date, '%Y-%m-%d'), '%M %d, %Y') date_new, unit, Descpt, p_cost, add_by, GROUP_CONCAT(color,' = ',qty) as COLOR, SUM(qty) as Total, SUM(qty*(p_cost)) as Ptotal from items where status IN ('1','2') Group By Descpt;
+---------------+------+------------------------+--------+--------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------+-----------+
| date_new | unit | Descpt | p_cost | add_by | COLOR | Total | Ptotal |
+---------------+------+------------------------+--------+--------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------+-----------+
| June 16, 2016 | Pcs | #1688N - Big Crate New | 125.00 | Psd | BLUE - W = 200,BLUE - W/O = 400,RED - W/O = 300,RED - W = 500,GREEN - W = 300,GREEN - W/O = 200,YELLOW - W = 400,YELLOW - W/O = 582,BLACK - W = 255,BLACK - W/O = 330 | 3467 | 900927.75 |
Color values will be print as column. how can I achieve it by select statement? attached is the needed output.