MySQL第五天

打印 上一主题 下一主题

主题 909|帖子 909|积分 2727

2022-09-07
1、Mysql中的清屏:
  1. system clear
复制代码
一般的清屏命令:clear
聚合函数
2、查询某个表中某个字段的值的个数(使用count)
以“students”表(字段有id,name,age,gender,height)为例:
  1. select count(id) from students;
复制代码
说明:select count(字段名) from 表名;
(2)统计表中的数据条数
  1. select count(*) from 表名;
复制代码
3、查询在约束条件下某个字段中的最大值
以“students”表为例:
  1. select max(id) from students where gender = 'girl';
复制代码
4、查询在约束条件下某个字段值的总和
以“students”表为例:
  1. select sum(height) from students where gender = 'boy';
复制代码
说明:select sum(字段名) from 表名 where 约束条件;
5、查询在约束条件下某个字段值的平均值
以“students”表为例:
  1. select avg(height) from students where gender = 'boy';
复制代码
说明:格式:select avg(字段名) from 表名 where 约束条件;
注意:如果统计某个字段中的值有NULL,则会跳过。所以,优化的语句为:
  1. select avg(ifnull(height,0)) from students where gender = 'boy';
复制代码
说明:如果为空,则设为0.
 

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

去皮卡多

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表