【发布时间】:2016-04-06 09:20:18
【问题描述】:
我有一个表格,其中有一列对内容进行分类:
id lang string
1 EN text1_en
1 DE text1_de
1 FR text1_fr
2 EN text2_en
2 DE text2_de
3 DE text3_de
3 FR text3_fr
我想得到这样的结果:
id lang string id lang string id lang string
1 EN text1_en 1 DE text1_de 1 FR text1_fr
2 EN text2_en 2 DE text2_de NULL NULL NULL
NULL NULL NULL 3 DE text3_de 3 FR text3_fr
我一开始尝试加入:
select
c1.id,c1.lang,c1.string,
c2.id,c2.lang,c2.string,
c3.id,c3.lang,c3.string
from
mytable c1
left join mytable c2 on (c1.id=c2.id and c2.lang='DE')
left join mytable c3 on (c1.id=c3.id and c3.lang='FR')
where
c1.lang='EN'
order by c1.id
但是我只得到 id 1 和 2 的结果。
如果我将 c1.lang='EN' 移动到 on 条件,我将获得前 3 列的所有表行(不仅是 lang='EN')
【问题讨论】:
-
我尝试了
where c1.lang not in ('DE','FR')和where c1.lang is null or c1.lang='EN',但仍然没有获得所需的第三行。