我有下表命名attributes
:
| identifier | attribute | value |
|------------|-----------|------------|
| 23 | myKey | myValue |
| 24 | hisKey | hisValue |
| 25 | herKey | herValue |
| 23 | otherKey | otherValue |
我想进行 SQL 选择查询,它选择上述行,按它们的标识符对它们进行分组,并使用attribute
作为键和value
作为键的值。
这意味着看起来像上面的表应该变成以下 PHP 数组:
Array
(
[0] => Array
(
[identifier] => 23
[myKey] => myValue
[otherKey] => otherValue
)
[1] => Array
(
[identifier] => 24
[hisKey] => hisValue
)
[2] => Array
(
[identifier] => 25
[herKey] => herValue
)
)
我尝试了以下 SQL 查询:
SELECT attributes.value as atttributes.attribute FROM attributes GROUP BY identifier
这将给出以下错误:
未捕获的异常“PDOException”,带有消息“SQLSTATE [42000]:语法错误或访问冲突:1064 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的“.attribute FROM attributes GROUP BY identifier”附近使用正确的语法
有谁知道这样做的方法?