前言
数据库名称可以为【schoolDB】,字符集【utf8】排序规则【utf8_general_ci】
1.建表语句———DDL
CREATE TABLE `student` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`creatDate` datetime DEFAULT NULL,
`userName` varchar(20) DEFAULT NULL,
`pwd` varchar(36) DEFAULT NULL,
`phone` varchar(11) DEFAULT NULL,
`age` tinyint(3) DEFAULT NULL,
`sex` char(2) DEFAULT NULL,
`introduce` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
2.插入语句————DML
insert into student values(0,'2024-02-25 10:00:00','刘德华','123456','12345678945',62,'男','六');
insert into student values(0,'2024-02-25 10:00:00','刘德华','123456','12345678945',62,'男','六');
insert into student(userName,age,introduce)values('刘亦菲',37,'漂亮');
3.基础查询语句————
#基础查询
select*from student;
#分列匿名以及筛选
select userName as'姓名',age 年龄,sex'性别',introuce'简介'
from student
where pwd is not null;
#去重查询
select distinct sex'性别类型'from student;
#排序查询
select userName as'姓名',age 年龄,sex'性别',introduce'简介' from student ORDER BY age desc;
#分页
#1个
select*from stuident LIMIT 2;
#2个
select*from student limit 4,2;
查询语句——DQL
SELECT*FROM`student`where userName like'张_';
SELECT*FROM`student`where userName like'刘%';
##
SELECT*FROM`student`where pwd is null;
SELECT*FROM`student`where pwd is not null;
##
SELECT*FROM`student`where age between 30 and 40;
SELECT*FROM`student`where creatDate between'2024-02-21 00:00:00' and'2024-02-23 00:00:00';
##
SELECT*FROM`student`where userName in('张翰','刘德华','刘亦菲');