mysql聚合函数的学习(未完,稍后写group by配合having)

x33g5p2x  于2021-11-22 转载在 Mysql  
字(0.5k)|赞(0)|评价(0)|浏览(463)

什么是聚合函数和聚集函数呢呢?

聚合函数就是把数据聚合起来的函数:对数据进行统计和分析

聚集函数是运行在行组上,计算和返回单个值的函数

1:count()用来计算表中记录的个数或者列中值的个数:select count(计算规范) from 表明

count(*) *:计数所有选择的行,包括NULL值

例如:查询办理一共有多少学生?:SELECT COUNT(*) FROM student

查询班上一共有多少男学生?:SELECT COUNT(*) FROM student WHERE grnder = '男'

count (all列名):计数指定列的所有非空值行,如果仅仅是默认指定列而不带all或者DISTINCT ,这是默认操作

例如:查询有多少个学生参加了sql考试:select count(all sqlScore) from student—>select count( sqlScore) from student

count(distinct 列名):技术指定列所有的唯一非空值行:select count(distinct age) from student

平均:select avg(sqlScore) from student

在计算平均值的时候,将空值过滤掉

ifnull:ifnull(expr1,expr2)判断是否为空值

round:

相关文章

微信公众号

最新文章

更多