【发布时间】:2015-11-09 07:25:03
【问题描述】:
我有一个这样的表结构:
|ID | Country | League |
| 0 | Germany | B1 |
| 1 | Germany | B2 |
| 2 | Italy | A |
如何通过查询只获得一次德国?我想要这样的东西:
Germany, Italy.
【问题讨论】:
我有一个这样的表结构:
|ID | Country | League |
| 0 | Germany | B1 |
| 1 | Germany | B2 |
| 2 | Italy | A |
如何通过查询只获得一次德国?我想要这样的东西:
Germany, Italy.
【问题讨论】:
选择distinct 值
select distinct country
from your_table
或按应该唯一的值分组
select country
from your_table
group by country
【讨论】:
你可以这样做:
SELECT DISTINCT country FROM some_table
这只会给你所有国家一次。
如果您希望在一个结果中包含所有国家/地区名称,您可以使用GROUP_CONCAT():
SELECT
GROUP_CONCAT(DISTINCT country ORDER BY country DESC SEPARATOR ',') AS country_list
FROM some_table
【讨论】: