插入表
select * from student where introduce like '%。';
select * from student where pwd is null;
select * from student where age between 150 and 200;
select * from student where
creatDate between '2024-02-24 00:00:00' and '2024-02-25 11:00:00';
select * from student where createDate>'2024-02-24 00:00:00'
and createDate<'2024-02-25 11:00:00';
select * from student where userName in ('女娲','蚩尤','伏羲');
select * from student where userName not in ('女娲','蚩尤','伏羲');
新建查询
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=1 DEFAULT CHARSET=utf8;
select * from student
聚合函数
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;