查询--单表查询

访问格式和顺序:

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 '\' --把字符串中_转换

 

 

 

 

 

 

 

 

 

  

  

posted @   山上的树  阅读(56)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· .NET Core 中如何实现缓存的预热?
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
· 【译】Visual Studio 中新的强大生产力特性
点击右上角即可分享
微信分享提示