你如何在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 |
+--------+----------+-------------------+
答案 0 :(得分:0)
这不是一个支点,只有GROUP BY
使用GROUP_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