疯狂编程网

  • 首页
  • 后端
    • GOLANG
    • PHP
  • 前端
  • 客户端
  • 服务器
  • AIGC
  • 开发工具
  • 代码人生
  • 关于本站
    • 联系我们
    • 免责声明
  1. 首页
  2. 服务器
  3. MYSQL
  4. 正文

MySQL第五天

2023年5月10日 120点热度 0人点赞 0条评论

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.

 

标签: mysql
最后更新:2023年5月10日

大明

靠写代码养家的开发者。

点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

COPYRIGHT © 2023 疯狂编程网. ALL RIGHTS RESERVED.

京ICP备2022013580号-1