查询--单表查询
访问格式和顺序:
1)Select...
2)from...3) where...
4)group by.... 5)having....
6)oreder by...
2 3 4 5 1 6
SELECT
select * from +表名 --查询全部
select 查询的列名 as可省略 别名 from 表名 --select Sno,Sname as ‘姓名’
select 中的子句可为表达式,字符串常量,函数,列别名等
select Sno,Cno,Grade*1.5 成绩,'河北师大' 学校 from SC
SELECT DISTINCT
select distinct 列名 --去重
select distinct Sno from SC
WHERE
select Sno,Sname from Student where Sno = 1
select Sno,Sname from Student where Sage>=20
BETWEEN...AND....
select Sno,Sname from Student where Sage between 20 and 30
select Sno,Sname from Student where Sage not between 20 and 30
IN
select Sno,Sname from Student where Sdept in('xx系','xx系')
等价于select Sno,Sname from Student where Sdept = 'xx系' or Sdept = 'xx系'
综合范例:
select Sname,Sdepe,Sage from Student where Ssex = '男' or (Ssex = '女' and Sage not in(20,23))--and优先级高于or select distinct Sno from SC where Cno in(1,2) and Grade >=90
LIKE 模糊查询
用ESCAPE将通配符进行转义 例如想要% _ escape '换码字符' 只转换紧随其后的第一个
where Sname like 'ab_c%' escape '\' --把字符串中_转换
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· .NET Core 中如何实现缓存的预热?
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
· 【译】Visual Studio 中新的强大生产力特性