我无法解决这个问题好几个小时。
这是我的桌子
t1:
–––––––––––––––––––––––––––––––––––
| id | text | lang | transl_id |
–––––––––––––––––––––––––––––––––––
| 1 | first | en | 222 |
–––––––––––––––––––––––––––––––––––
| 2 | second | de | 222 |
–––––––––––––––––––––––––––––––––––
| 3 | jkj | de | 234 |
–––––––––––––––––––––––––––––––––––
| 4 | 89080 | de | 235 |
–––––––––––––––––––––––––––––––––––
这是我的查询:
SELECT
transl_id AS property,
(SELECT text FROM t1 WHERE lang='en') AS value1,
(SELECT text FROM t1 WHERE lang='de') AS value2,
FROM t1
它返回下表:
–––––––––––––––––––––––––––––––––––
| property | value1 | value2 |
–––––––––––––––––––––––––––––––––––
| 222 | first | |
–––––––––––––––––––––––––––––––––––
| 222 | | second |
–––––––––––––––––––––––––––––––––––
| 234 | jkj | |
–––––––––––––––––––––––––––––––––––
| 235 | 89080 | |
–––––––––––––––––––––––––––––––––––
每行都有一个value1
或value2
,从不兼有。有没有办法对结果进行分组,以便property
字段值相等的行在一行中?我的意思是这样的:
–––––––––––––––––––––––––––––––––––
| property | value1 | value2 |
–––––––––––––––––––––––––––––––––––
| 222 | first | second |
–––––––––––––––––––––––––––––––––––
...