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 NULL COMMENT '性别',
`introduce` varchar(255) DEFAULT NULL COMMENT '简介',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8;
练习表
#聚合函数会涉及到5个单词: 数量count()、最大max()、最小值min()、平均数avg()、求和sum()
select count(*) '数据总条数' from student where pwd is not null;
select max(age) '年龄最大' from student;
select min(age) '年龄最小' from student;
select avg(age) '平均年龄' from student;
select sum(age) '年龄总和' from student;
#使用年龄综合计算一下平均数
select sum(age)/(select count (*) '数据总条数' from student) '平均年龄' from student;