MYSQL 聚合函数 --AVG MAX MIN COUNT SUM

1.DDL

CREATE TABLE `student` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '学号',
  `createDate` datetime DEFAULT NULL COMMENT '创建日期',
  `userName` varchar(20) DEFAULT NULL COMMENT '姓名',
  `pwd` varchar(36) DEFAULT NULL COMMENT '密码',
  `phone` varchar(11) DEFAULT NULL COMMENT '手机号',
  `age` tinyint(3) unsigned DEFAULT NULL COMMENT '年龄',
  `sex` char(2) DEFAULT '男' COMMENT '性别',
  `introduce` varchar(255) DEFAULT NULL COMMENT '介绍',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=29 DEFAULT CHARSET=utf8;

2.DML

INSERT INTO `student` VALUES (21, '2024-02-25 10:10:10', '马牛', '123456', '15612345678', 20, '女人', '团长');
INSERT INTO `student` VALUES (22, '2024-02-25 10:10:10', '丁成', '123457', '15612345698', 19, '女人', '队员');
INSERT INTO `student` VALUES (23, '2024-02-25 10:10:10', '宋亚', '123466', '15612349678', 20, '女人', '队员');
INSERT INTO `student` VALUES (24, '2024-02-25 10:10:10', '张员', '129456', '15662345678', 21, '女人', '队员');
INSERT INTO `student` VALUES (25, '2024-02-25 10:10:10', '严翔', '183456', '15612345678', 22, '女人', '队员');
INSERT INTO `student` VALUES (26, '2024-02-25 10:10:10', '贺军', '123459', '15612344678', 24, '女人', '队员');
INSERT INTO `student` VALUES (27, '2024-02-25 10:10:10', '刘为', '123456', '15612345678', 23, '女人', '队员');
INSERT INTO `student` VALUES (28, NULL, '悠悠球琛

3.DQL

select count(*) from student where age < 25;
select max(age)  from student;
select min(age)  from student;
select avg(age) from student;
select sum(age)/(select count(*) from student) 'sum计算平均年龄',avg(age)'平均年龄'from student;

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值