MySQL常用聚合函数详解
一、AVG
AVG(col)
返回指定列的平均值
二、COUNT
COUNT(col)
返回指定列中非NULL值的个数
三、MIN/MAX
MIN(col):返回指定列的最小值
MAX(col):返回指定列的最大值
四、SUM
SUM(col)
返回指定列的所有值之和
五、GROUP_CONCAT
GROUP_CONCAT([DISTINCT] expr [,expr ...]
[ORDER BY {unsigned_integer | col_name | expr}
[ASC | DESC] [,col_name ...]]
[SEPARATOR str_val])
返回由属于一组的列值连接组合而成的结果
SELECT id,GROUP_CONCAT(name) FROM my_table GROUP BY id; SELECT id,GROUP_CONCAT(name separator ';') FROM my_table GROUP BY id; SELECT id,GROUP_CONCAT(name order by id) FROM my_table GROUP BY id; SELECT id,GROUP_CONCAT(name order by id separator ';') FROM my_table GROUP BY id;
相关推荐
ztyzly00 2020-06-12
zycchun 2020-03-15
Lius 2020-05-11
wenjieyatou 2020-05-08
xuanlvhaoshao 2020-02-20
李玉志 2020-02-02
ztyzly00 2020-01-12
jiahaohappy 2019-12-29
herohope 2019-12-22
阿亮 2019-10-31
落地窗前梦残夜 2019-06-29
tuxlcsdn 2019-06-28
Depth 2019-06-27
世樹 2019-05-22
LinoHngJie 2019-04-16
programmerv 2019-06-20
异道 2019-01-07
mrandy 2019-02-10