ToB企服应用市场:ToB评测及商务社交产业平台
标题:
MySQL第五天
[打印本页]
作者:
去皮卡多
时间:
2022-9-17 08:39
标题:
MySQL第五天
2022-09-07
1、Mysql中的清屏:
system clear
复制代码
一般的清屏命令:clear
聚合函数
2、查询某个表中某个字段的值的个数(使用count)
以“students”表(字段有id,name,age,gender,height)为例:
select count(id) from students;
复制代码
说明:select count(字段名) from 表名;
(2)统计表中的数据条数
select count(*) from 表名;
复制代码
3、查询在约束条件下某个字段中的最大值
以“students”表为例:
select max(id) from students where gender = 'girl';
复制代码
4、查询在约束条件下某个字段值的总和
以“students”表为例:
select sum(height) from students where gender = 'boy';
复制代码
说明:select sum(字段名) from 表名 where 约束条件;
5、查询在约束条件下某个字段值的平均值
以“students”表为例:
select avg(height) from students where gender = 'boy';
复制代码
说明:格式:select avg(字段名) from 表名 where 约束条件;
注意:如果统计某个字段中的值有NULL,则会跳过。所以,优化的语句为:
select avg(ifnull(height,0)) from students where gender = 'boy';
复制代码
说明:如果为空,则设为0.
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/)
Powered by Discuz! X3.4