0

このテーブルを MySQL でどのようにピボットしますか? 日付順です。

+--------+----------+-----------+
| grpid  | status   | msg       |
+--------+----------+-----------+
|      1 | OK       | text6     |
|      1 | PROGRESS | text5     |
|      1 | PROGRESS | text4     |
|      2 | FAIL     | text3     |
|      2 | PROGRESS | text2     |
|      2 | PROGRESS | text1     |
+--------+----------+-----------+

このフォームに:

+--------+----------+-------------------+
| grpid  | status   | progress          |
+--------+----------+-------------------+
|      1 | OK       | text4,text5,text6 |
|      2 | FAIL     | text1,text2,text3 |
+--------+----------+-------------------+
4

1 に答える 1

0

これはピボットではなく、GROUP BYusingGROUP_CONCAT()です:

SELECT   grpid,
         GROUP_CONCAT(CASE WHEN status IN ('OK','FAIL') THEN status END) AS status,
         GROUP_CONCAT(msg) AS progress
FROM     my_table
GROUP BY grpid
于 2012-05-11T08:01:24.723 に答える