0
我有一个table1,我在努力尝试获取类似于table2的输出 。有任何想法吗 ?MYSQL根据列字符串将值拆分为多个列
表1
+-----+-----------+------+----------+---------------------+
| id | Sensor | Temp | Humidity | DateTime |
+-----+-----------+------+----------+---------------------+
| 1 | Sens1 | 9.7 | 55 | 2015-02-21 11:29:47 |
| 2 | Sens2 | 4.4 | 99 | 2015-02-21 11:45:00 |
| 3 | Sens1 | 9.8 | 56 | 2015-02-21 11:44:59 |
| 4 | Sens2 | 4.5 | 98 | 2015-02-21 11:59:24 |
+-----+-----------+------+----------+---------------------+
输出想要的东西: 表2
+---------------------+-----------+----------+-----------+----------+
| Datetime | Sens1temp | Sens1hum | Sens2temp | Sens2hum |
+---------------------+-----------+----------+-----------+----------+
| 2015-02-21 11:29:47 | 9.7 | 55 | null | null |
| 2015-02-21 11:45:00 | null | null | 4.4 | 99 |
| 2015-02-21 11:44:59 | 9.8 | 56 | null | null |
| 2015-02-21 11:59:24 | null | null | 4.5 | 98 |
+---------------------+-----------+----------+----------+-----------+
我已经花了几个小时寻找,但只是无法得到它的工作。
这里我们不需要MAX :) CASE就够了imho – Alex 2015-02-23 19:37:47
@Alex:是的!对!更新了我的答案。 – 2015-02-23 19:40:56