- 9
- 0
- 约5.48千字
- 约 4页
- 2016-12-03 发布于贵州
- 举报
SQL 运符及模糊查询,空字段的处理等等.
语句所用表说明
第二章:select 语句:where子句过滤
1.And 和 or 运算符
and运算符用于连接两个布尔型表达式,当有所有表达式都为true时返回true,当有一个表达式返回为false时则返回false
语法:Boolean_experssion and Boolean_experssion
(1).利用图书销售表查询图书编号是1100010101和销售数量为2的图书单价
Select b_price from Bookinfo where b_code=’1100010101’ and b_number = 2
or运算符也是用于连接两个布尔型表达式,但是当表达式有一个为flase则返回false,
语法:Boolean_experssion or Boolean_experssion
(1).利用图书信息表(Bookinfo)查询图书编号(b_code)是1100010101或者是1100010102的所有图书信息
Select * from Bookinfo where b_code=’1100010101’ or b_code = ‘1100010102’
注意:and优先级大于or优先级,要想改变优先级的级别,则用小括号括起来
2.比较用算符
比较用算符:
运算符 说明 = 等于号 大于号 小于号 = 大于等于号 = 小于等于号 ! 不大于 ! 不小于 或者!= 不等于 (1).查询学生表中年龄为22学生的所有信息
Select * from studenttable where studentage = ‘21’
(2).查询学生表中学号大于6的学生所有信息
Select * from studenttable where studentid6
(3).查询学生表中年龄小于21岁学生所有信息
Select * from studenttable where studentage21
(4).查询学生表中年龄大于等于23岁学生所有信息
Select * from studenttable where studentage =23
(5).查询学生表中学号小于等于3的学生所有信息
Select * from studenttable where studentid=3
(6).查询学生表中学号不大于3的学生所有信息
Select * from studenttable where studentid !3
(7). 查询学生表中学号不小于3的学生所有信息
Select * from studenttable where studentid!3
(8). 查询学生表中年龄不是24的学生所有信息
Select * from studenttable where studentage !=24
Select * from studenttable where studentage 24
3.in运算符
In运算符是根据给定的值进行查询数据的,它的作用和or的作用是相同的, 但是用起来却比or方便
语法:test_expression [not] in(subquery|expression[…n])
查询图书销售表中图书编号(b_code)为01或者02的记录
Select *from Booksales where b_code in (‘1100010101’,’1100010102’)
查询图书销售表中图书单价为88的记录
Select * from Booksales where b_price in (66+22)
查询图书销售表中图书单价为59.8的记录
Select * from Booksales where 59.8 in (b_price)
查询图书销售表中图书编号不为01或者02的记录
Select * from Booksales where b_code not in (‘1100010101’,’1100010102’)
查询图书销售表中图书单价不为88或者58.8记录
Select * from Booksales where b_price not in (77+11,58+0.8)
查询图书销售表中图书单价不为88的记录
Select * from Booksales where 88 not in (b_price)
4.between…and 和not between …and 查找指定范围数据
Between …and 是查询指定范围内的数据,
语法:test_expression [not]between begin_expression and end_expression
查询学生表中年龄在20到2
您可能关注的文档
最近下载
- 潍坊市2026届高三高考模拟考试(一模)英语试卷(含答案).pdf
- 机械工程图学-机械制图的基本知识(制图标准).pdf VIP
- 2025 AHA指南电除颤要点解读PPT.pptx VIP
- 江苏省镇江市中考物理一模试卷.doc VIP
- 2024年江苏省镇江市中考一模物理试卷.doc VIP
- Insta360影石GO2快速说明书.pdf
- 中国古代建筑艺术(拼接).pptx VIP
- 2026年创业者的危机管理与应急预案.pptx VIP
- Unit 3 课时4 Lesson 4(课件)-2025-2026学年八年级英语下册(冀教版2024).pptx
- 宫颈机能不全诊治中国专家共识(2025版).pptx VIP
原创力文档

文档评论(0)