mysql pivot data


/ Published in: SQL
Save to your folder(s)

pivot data. input source query in the form :

+--------+-----------+-------------+-------------+
| name | pivot_fid | pivot_fname | pivot_value |
+--------+-----------+-------------+-------------+
| apple | 1 | is red | 1 |
| apple | 2 | is blue | 0 |
| orange | 1 | is red | 1 |
| orange | 2 | is blue | 0 |
+--------+-----------+-------------+-------------+

and fields to pivot around ( eg. name ), outputs :

+--------+--------+---------+
| name | is red | is blue |
+--------+--------+---------+
| apple | 1 | 0 |
| orange | 1 | 0 |
+--------+--------+---------+

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.