MySQL查询语句like-between-and

 前言

数据库名称可以为【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('张翰','刘德华','刘亦菲');

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值