Mysq-DQL操作表_条件查询(查询*重点)

image
image
image

image
image
image
image
image

image
--基础查询 --查询 NAME 和 age两列
SELECT
NAME
,
age
FROM
stu;
--查询所有列的数据
SELECT
*
FROM
stu;
--查询地址信息
SELECT address from stu;
--使用DISTINCT去除重复记录
SELECT DISTINCT address from stu;

--查询姓名,数学成绩,英语成绩
select name,math,english from stu;

--给要查询的列 使用as 起别名
select name ,math 数学成绩,english as 英语成绩 from stu;

select * from stu;
--条件查询
--查询年龄大于20岁的学员信息;
SELECT * from stu where age>20;
--查询年龄大于等于20岁的学员信息;
SELECT * from stu where age>=20;

--查询年龄大于等于20岁,并且年龄小于等于30岁的学员信息;
SELECT * from stu where age BETWEEN 20 and 30;
SELECT * from stu where age >=20 and age <=30;
SELECT * from stu where age >=20 && age <=30;

--查询入学日期在1998-09-01 到1999-09-01之间的学员信息
SELECT * from stu where hire_date BETWEEN '1998-09-01' and '1999-09-01';

--查询年龄等于18岁的学员信息;
SELECT * from stu where age=18;

--查询年龄不等于18岁的学员信息;
SELECT * from stu where age!=18;
SELECT * from stu where age<>18;

--查询年龄等于18岁或者年龄等于20岁或者年龄等于22岁的学员信息;
SELECT * from stu where age in (18,20,22);
SELECT * from stu where age=18 or age=20 or age =22;

--查询英语成绩为null的成绩;

--注意Null的比较不能使用= !=,需要使用is is not 来比较;

select * from stu where english is null;

SELECT * from stu where english is not null;

--模糊查询 like

/*
通配符:
(1):_:代表单个任意字符
(2):%:代表任意个数字符

*/
--查询姓'马'的学员信息;
SELECT * from stu where name like '马%';

--查询第二个字是'花'的学员信息
SELECT * from stu where name like '_花%';

--查询名字中包含'德'的学员信息;
SELECT * from stu where name like '%德%';

posted @ 2022-11-10 00:21  NiceTwocu  阅读(23)  评论(0编辑  收藏  举报