建立‘学生表’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 '男',
`introduce` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
插入语句DML
insert into student values(0,'2024-02-17 10:10:10','赵灵儿','123',
'15612345678',16,'女','逍遥哥哥,你终于找到我了。');
insert into student values(0,'2024-02-29 10:10:10','王语嫣','123',
'15612345678',17,'女','慕容复,我和你不共戴天。');
insert into student values(0,'2024-02-19 10:10:10','龙姑娘','123',
'15612345678',22,'女','我想过过过儿过过的日子。');
insert into student values(0,'2024-02-23 10:10:10','杨过','123',
'15612345678',18,'男','一遇杨过误终身。');
insert into student values(0,'2024-02-28 10:10:10','杨逍遥','123',
'15612345678',27,'男','杨过跟程英的大儿子。');
insert into student (userName,age,introduce)values('黄衣女子',26,'杨过与龙姑娘的大女儿。');
查询语句DQL
# like 模糊查询
select * from student where userName like '杨%';
select * from student where userName like '杨_';
# is (not) null 查询
select * from student where pwd is null;
select * from student where pwd is not null;
# between [start] and [end] 数值/时间之间范围
select * from student where age between 15 and 25;
select * from student where createDate between '2024-02-20' and '2024-03-01';
# in 用于多个数据查询,不走索引(就是数据多了卡)
select * from student where userName in('赵灵儿','杨逍遥','龙姑娘');