任何人都可以帮助我如何使用源表上的行数据作为输出的标题来创建查询输出。请参阅下面的说明。
例如
行数据:
+-----------+----------+
| colHeader | value |
+-----------+----------+
| Header1 | value 1 |
+-----------+----------+
| Header2 | value 2 |
+-----------+----------+
| Header3 | value 3 |
+-----------+----------+
输出:
+-----------+-----------+-----------+
| Header1 | header2 | Header3 |
+-----------+-----------+-----------+
| Value 1 | value 2 | Value 3 |
+-----------+-----------+-----------+
可能吗??
这是我的 MySQL 脚本。我不认为这是正确的方法。对我如何获得上述输出有任何想法吗?
SELECT t1.value AS `Header1`,
t2.value AS `Header2`,
t3.value AS `Header3`
FROM (SELECT * FROM table1 WHERE colHeader='Header1') t1
JOIN (SELECT * FROM table1 WHERE colHeader='Header2'3) t2
JOIN (SELECT * FROM table1 WHERE colHeader='Header3') t3;