MySQL之group_concat 配合substring_index查询

功能:将group by产生的同一个分组中的值连接起来,返回一个字符串结果。

用法:group_concat([DISTINCT] 要连接的字段 [Order BY ASC/DESC 排序字段] [Separator '分隔符'])

字符串截取:substring_index(str,delim,count)

例如查询每个用户的最大投资额:

select investoruserid,substring_index(group_concat(investamount order by investamount desc separator ','),',',1) from loan_investor group by investoruserid; 

原文地址:https://www.cnblogs.com/huangxiaoying/p/5923041.html