我有一个翻译要求:
(表结构:
线路id
lang(“en”或“ru”)
文本
所以,在桌子上看起来:
5 | en | Test
6 | en | Hello!
7 | en | Another words
6 | ru | Привет!
所有翻译都在同一个表中,关键字行是独立于语言的)
SELECT txt.line_id, txt.text AS o, ru.text AS t
FROM text AS txt, text AS ru
WHERE txt.line_id = ru.line_id
AND txt.lang = 'en';
它将返回这样的数组
> [5] => Array ( [line_id] => 5 [o] => Test [t] => Test
> [6] => Array ( [line_id] => 6 [o] => Hello! [t] => Hello! )
> [7] => Array ( [line_id] => 6 [o] => Hello! [t] => Привет! )
o-是原文,t-翻译。
如何从集合6行中删除,因为我们在下一行中有翻译。按组将杀死7行并保存6行。
最好的结果是:
> [5] => Array ( [line_id] => 5 [o] => Test [t] => )
> [6] => Array ( [line_id] => 6 [o] => Hello! [t] => Привет! )
没有[o]=>你好![t]=>你好!
最佳答案
我想你可能需要:
SELECT txt.line_id,
txt.text AS o,
COALESCE (ru.text,'UNTRANSLATED') AS t
FROM
text AS txt
LEFT JOIN
text AS ru
ON txt.line_id=ru.line_id AND ru.lang='ru'
WHERE txt.lang='en'
关于mysql - MySQL:如何从集合中删除行?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8960467/