-1

I want to transfer the table :

platform | count
Android    100
IOS         200

to

Android | IOS
100           200

IN MYSQL USING QUERY

How can I do It ?

Thanks

Bill Karwin
  • 538,548
  • 86
  • 673
  • 828
yardenn
  • 29
  • 2

1 Answers1

0

You need to look up pivot tables and how they work.

To tabulate all colID and value values against all id values—that is, to write a reporting CUBE for the table—write a GROUP_CONCAT() instruction for each colID found in the table, then GROUP BY id:

SELECT  
  id,  
  GROUP_CONCAT(if(colID = 1, value, NULL)) AS 'First Name', 
  GROUP_CONCAT(if(colID = 2, value, NULL)) AS 'Last Name', 
  GROUP_CONCAT(if(colID = 3, value, NULL)) AS 'Job Title' 
FROM tbl 
GROUP BY id; 
+------+------------+-----------+----------------+ 
| id   | First Name | Last Name | Title          | 
+------+------------+-----------+----------------+ 
|    1 | Sampo      | Kallinen  | Office Manager | 
|    2 | Jakko      | Salovaara | Vice President | 
+------+------------+-----------+----------------+ 

A quick google search led me to this explanation here which answers your question and then some: http://www.artfulsoftware.com/infotree/qrytip.php?id=78

catbadger
  • 1,662
  • 2
  • 18
  • 27