DQL基础查询/条件查询
基础查询:
select name,age from stu; -- 查两列
select * from stu; -- 查全部,不推荐
select distinct address from stu; --查一列去除重复数据
select name,math as 数学成绩,english as 英语成绩 from stu; -- 给列起别名
select name,math 数学成绩,english 英语成绩 from stu; --as可以省略
条件查询:
大于/小于:
select * from stu where age>20; -- 大于20
大于等于/小于等于:
select * from stu where age>=20; -- 大于等于20
等于:
select * from stu where age=20; -- 等于20,注意是一个等号
不等于:
select * from stu where age!=20; -- 不等于20
select * from stu where age<>20; -- 不等于20,<>和!=作用相同
与:
select * from stu where age>=20 && age<=30; -- 大于等于20并且小于等于30
select * from stu where age>=20 and age<=30; -- &&与and作用一样
特例:between ...and...:
select * from stu where age between 20 and 30; -- between...and...与&&与and作用一样
或:
select *from stu where age=10 or age=20 or age=30;
特例:in
select *from stu where age in (10,20,30)
null:
select *from stu where english is null; -- 查空数据
select *from stu where english is not null; -- 查不为空的数据
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!