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.

 

posted @   努力是一种常态  阅读(76)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
点击右上角即可分享
微信分享提示