student建表DDL
CREATE TABLE `student` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '学号',
`createDate` datetime DEFAULT NULL,
`userName` varchar(20) DEFAULT NULL,
`pwd` varchar(36) DEFAULT NULL,
`phone` varchar(11) DEFAULT NULL,
`age` tinyint(3) unsigned DEFAULT NULL,
`sex` char(2) DEFAULT NULL,
`introduce` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;
插入数据DML语句
insert into student values(0,'2024-02-25 10:10:10','盘古','123456','13412341234',255,'神','开天辟地。');
insert into student values(0,'2024-02-25 10:10:10','女娲','123456','13412341234',200,'神','造人。');
insert into student values(0,'2024-02-25 10:10:10','伏羲','123456','13412341234',215,'神','先天八卦。');
insert into student values(0,'2024-02-25 10:10:10','神农','123456','13412341234',155,'神','尝百草。');
insert into student values(0,'2024-02-25 10:10:10','祖','123456','13412341234',255,'神','养蚕织布。');
insert into student values(0,'2024-02-25 10:10:10','蚩尤','123456','13412341234',255,'神','锻造大神。');
insert into student (userName,age,introduce)values('仓颉','255','象形文字。');
聚合函数
select count(*) from student where pwd is not null;
select max(age) '最大年龄',min(age) '最小年龄' from student;
select sum(age) '总年龄' from student;
select avg(age) '平均年龄' from student;
select sum(age)/(select count(*) from student) 'sum计算平均年龄',avg(age)'平均年龄' from student;
标签:10,聚合,函数,DEFAULT,age,student,MySQL,NULL,into
From: https://blog.csdn.net/2401_83904918/article/details/137269207