help with mysql query - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: help with mysql query (/showthread.php?tid=67047) |
help with mysql query - gosatriani - 01-07-2017 Hi All, i have a table in mysql with the following data Code: Table name Test i am looking for a mysql query which will give the below mentioned output Code: RE: help with mysql query - badger - 01-08-2017 you need a pivot like SELECT t.asset, SUM(IF(t.`status`="In Stock",1,0)) AS "In_Stock", SUM(IF(t.`status`="Allocated",1,0)) AS "Allocated", SUM(IF(t.`status`="Decommissioned",1,0)) AS "Decommissioned", t.location FROM tester t GROUP BY t.asset, t.location Bill |