Mysq-DQL操作表_条件查询(查询*重点)
--基础查询 --查询 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 '%德%';
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 葡萄城 AI 搜索升级:DeepSeek 加持,客户体验更智能
· 什么是nginx的强缓存和协商缓存
· 一文读懂知识蒸馏