MySQL - 行到列
我试图搜索帖子,但我只找到了SQL Server / Access的解决方案。我需要一个MySQL(5.X)的解决方案。
我有一个表(称为历史)有3列:hostid,itemname,itemvalue。
如果我执行select(select * from history),它将返回
+--------+----------+-----------+
| hostid | itemname | itemvalue |
+--------+----------+-----------+
| 1 | A | 10 |
+--------+----------+-----------+
| 1 | B | 3 |
+--------+----------+-----------+
| 2 | A | 9 |
+--------+----------+-----------+
| 2 | c | 40 |
+--------+----------+-----------+
如何查询数据库以返回类似的内容
+--------+------+-----+-----+
| hostid | A | B | C |
+--------+------+-----+-----+
| 1 | 10 | 3 | 0 |
+--------+------+-----+-----+
| 2 | 9 | 0 | 40 |
+--------+------+-----+-----+
慕田峪9158850
萧十郎
相关分类