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=15 DEFAULT CHARSET=utf8;
select* from student where introduce like '%天%'
#空查询
select * from student where pwd is null;
#范围查询between 小数值 and 大数值
select * from student where age between 150 and 200;
select * from student where
createDate between '2024-02-20 00:00:00' and '2024-02-24 11:00:00';
#in 关键字,非必要不建议使用,一般不走索引,数据量超过百万就报卡。
select * from student where userName in ('女娲','蚩尤','伏羲');
select * from student where userName not in ('女娲','蚩尤','伏羲');
聚合函数涉及的五个单词、
#聚合函数会涉及5个单词:数量count()、最大max()、平均数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;