MYSQL:选择状态相同的客户

时间:2015-04-16 10:28:19

标签: mysql

需要提供一个产生结果的select语句:

State Name   customer1 customer2

我知道我需要使用concat()我只是不确定如何识别具有相同状态的客户

任何帮助表示赞赏

1 个答案:

答案 0 :(得分:2)

您需要group_concat

select
state,
group_concat(customer_name) as customers
from table_name
group by state;

请注意,对于大型数据,您需要重置group_concat_max_len

的值

https://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#sysvar_group_concat_max_len

相关问题