创建数据表——DDL
CREATE TABLE `student` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '学号',
`createDate` datetime DEFAULT NULL COMMENT '创建时间',
`userName` varchar(20) DEFAULT NULL COMMENT '用户名',
`psw` varchar(36) DEFAULT NULL COMMENT '密码',
`phone` varchar(11) DEFAULT NULL COMMENT '手机号',
`age` tinyint(3) unsigned DEFAULT NULL COMMENT '年龄',
`sex` char(2) DEFAULT NULL COMMENT '性别',
`introduce` varchar(255) DEFAULT NULL COMMENT '简介',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;
插入语句——DML
insert into student values(0,'2024-2-25 10:10:10','盘古','123456','15678946454',
255,'神','开天辟地第一人');
insert into student values(0,'2024-2-25 10:10:10','女娲','123456','15678946454',
215,'女','多次造人最终成功');
insert into student values(0,'2024-2-25 10:10:10','伏羲','123456','15678946454',
155,'神','先天八卦');
insert into student values(0,'2024-2-25 10:10:10','神农','123456','15678946454',
115,'神','尝百草,死于断肠草下');
insert into student values(0,'2024-2-25 10:10:10','嫘氏','123456','15678946454',
255,'神','教会百姓养蚕织布');
insert into student values(0,'2024-2-25 10:10:10','蚩尤','123456','15678946454',
155,'神','锻造大神,坐下食铁巨兽');
insert into student (userName,age,introduce) values ('仓颉',123,'中国象形文字');
聚合函数sum_avg_max_min_count
#五个常用的聚合函数 count(x)计数的 max(x) min(x) 最大值最小值 avg(x)
select count(*) from student where pwd is not null ;
select age(max)'最大年龄',min(age)'最小年龄'from student;
select sum(age) '总年龄'from student;
select avg(age)'平均年龄'from student;
#利用sum单独计算一下平均数
select sum(age)/(select count(*) from student)'sum计算平均年龄',avg(age)'平均年龄'from student;