我有这个表(url\u表):
+----+---------------+-------------+
| id | language_code | url |
+----+---------------+-------------+
| 60 | de | german_url |
| 60 | en | english_url |
| 60 | fr | france_url |
| 60 | es | spanish_url |
+----+---------------+-------------+
我想将这两个查询合并为一个:
SELECT url FROM url_table WHERE id = 60 AND language_code = 'de';
SELECT url FROM url_table WHERE id = 60 AND language_code = 'en';
结果应为德语和英语url,但重命名为url\u de和url\u en:
url_de: german_url
url_en: english_url
5条答案
按热度按时间0kjbasz61#
你可以用
OR
```SELECT url FROM url_table WHERE id = 60 AND language_code = 'de' OR language_code = 'en' ;
zfycwa2u2#
我认为您需要聚合或加入:
这将适用于任意数量的
id
如果你使用group by
:也可以使用自联接:
但是,如果两种语言都没有行,这就很棘手了,这就是为什么我推荐
group by
接近。ergxz8rk3#
不确定语法是否完美,但可能是这样的。
monwx1rj4#
试试这个
输出:
8yoxcaq75#
你可以试着用
in
```SELECT url
FROM url_table
WHERE id = 60 AND language_code in ('de','en');
SELECT concat('url_',language_code ,':',url)
FROM url_table
WHERE id = 60 AND language_code in ('de','en');