group by having 子句查询

group by having clause query

客户table: (ID, 名, 姓, 城市, 国家, Phone)

** 列出每个国家/地区的客户数量。仅包括拥有 1 个以上客户的国家/地区。 --> 查询如下

 SELECT COUNT(Id), Country
    FROM Customer
    GROUP BY Country
    HAVING COUNT(Id) > 1

Results: 3 records
Count   Country
2   France
4   Germany
3   USA

问题: 我需要获取这些计数的名称,即。同一查询中的 FirstName EG : 如下

Results: 3 records
    Count   Names             Country
    2       john,max          France
    4       abc,xyz,aab,cdf   Germany
    3       mmm,fmf,dm        USA

可能吗?

试试这个:

select count(id) as count,
       group_concat(first_name),
       country
from Customer
group by country

Group_concat 函数returns 一个字符串,该字符串与组中的非 NULL 值连接。