https://www.mysqltutorial.org/mysql-group_concat/
sql45题中的第9题,用到了group_concat() https://www.cnblogs.com/chentianwei/p/12128269.html
sql45题中的例子:
select * from sc where sid = "01"; +------+------+-------+ | SId | CId | score | +------+------+-------+ | 01 | 01 | 80.0 | | 01 | 02 | 90.0 | | 01 | 03 | 99.0 | +------+------+-------+
select group_concat(cid) from sc where sid = "01"; +-------------------+ | group_concat(cid) | +-------------------+ | 01,02,03 | +-------------------+
The MySQL GROUP_CONCAT()
function is an aggregate function that concatenates strings from a group into a single string with various options.
把一列数据聚合成一个单一的string。有几个参数:
GROUP_CONCAT( DISTINCT expression ORDER BY expression SEPARATOR sep );
原文:https://www.cnblogs.com/chentianwei/p/12134040.html