原始数据:
code | name | z_date |
---|---|---|
1 | aaa | 20241220 |
1 | aaa | 20241221 |
1 | aaa | 20241222 |
2 | bbb | 20241219 |
2 | bbb | 20241220 |
输出结果:
code | name | z_date |
---|---|---|
1 | aaa | 20241220,20241221,20241222 |
2 | bbb | 20241219,20241220 |
SQL:
select code,name,count(n),GROUP_CONCAT(z_date order by z_date asc SEPARATOR ', ') from z_data group by code,name order by 3 desc;
标签:code,aaa,name,bbb,拼接,mysql,date,某字段,20241220
From: https://www.cnblogs.com/stxz/p/18628245