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 BYusing 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
于 2012-05-11T08:01:24.723 回答