MySQL之group_concat 配合substring_index查询

时间:2023-01-03 11:02:04

字符串连接: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;