SQL查询初学者指南读书笔记(四)where从句
来源:互联网 发布:kindle保护套推荐 知乎 编辑:程序博客网 时间:2024/05/01 07:16
CHAPTER6 Filtering Your Data
本章介绍WHERE从句.
predicates
Comparison,BETWEEN,IN, LIKE, and IS NULL.
We’ll cover the other two—Quantified and EXISTS—in Chapter 11, Subqueries.
Comparison
Equality and Inequality
= ,<>
Less Than and Greater Than
<,>
less than or equal to
<=
greater than or equal to
>=
combine comparisons using AND and OR
Range
The BETWEEN . . . AND predicate defines the range by using the value of the second value expression
as the start point and the value of the third value expression as the end point.
Both the start point and end point are part of the range.
习惯使用 (Value Expression1 <= Value Experssion2) and (Value Expression1 >= Value Experssion3)的各位同学,可以考虑使用BETWEEN . . . AND替代,这样SQL语句会更容易阅读理解.
Set Membership
Pattern Match
A pattern string can consist of any logical combination of regular string characters and
two special wildcard characters: the percent sign (%) and the underscore (_).
The percent sign represents zero or more arbitrary regular characters, and the underscore represents a single arbitrary regular character.
%与_通配符类似于正则表达式中的*与?
遇到通配符与正常字符混淆的情况怎么办?比如我们需要匹配含有下划线的字符串怎么办?这也是功能字符包含在常规字符会遇到的混淆情况,编码中经常碰到.这时我们需要将功能字符转义为常规字符,我们使用ESCAPE关键字实现这个功能.
举个例子,一目了然:
“Show me a list of products that have product codes beginning with‘G_00’ and ending in a single number orletter.”
SQL SELECT ProductName, ProductCode
FROM Products
WHERE ProductCode LIKE 'G\_00_' ESCAPE '\'
Keep in mind that the character you use as an escape character should not be
part of the values you’re trying to retrieve.
Null
判断Value Expression是否为NULL的时候请不要使用Value Expression = NULL,这是常犯的小错误.
Excluding Rows with NOT
Order of Precedence
When you treat a combined set of conditions as a single unit, by definition it becomes a
search condition, and you must enclose it in parentheses.
添加括号以避免可能的混淆.
When you need to use multiple conditions, make certain that the condition that excludes the
most rows from the result set is processed first so that your database can
potentially find the answer faster.
- SQL查询初学者指南读书笔记(四)where从句
- SQL查询初学者指南读书笔记(二)创建SQL查询
- SQL查询初学者指南读书笔记(三)值表达式
- SQL查询初学者指南读书笔记(五)集合操作与多表查询介绍
- SQL查询初学者指南读书笔记(一)关系数据库和SQL介绍
- 警惕 MySql 更新 sql 的 WHERE 从句中的 IN() 子查询时出现的陷阱
- 警惕 MySql 更新 sql 的 WHERE 从句中的 IN() 子查询时出现的陷阱
- 警惕 MySql 更新 sql 的 WHERE 从句中的 IN() 子查询时出现的陷阱
- SQL(四)查询(二)过滤数据(where子句()
- sql查询where/in
- MY SQL初学者指南
- 《语法俱乐部》读书笔记 从句
- SQL WHERE(条件查询)
- where引导的定语从句与状语从句区别
- SQL的join从句
- SQL读书笔记(四)
- Hibernate读书笔记-----SQL查询
- oracle where 和having从句区别
- My97DatePicker
- dubbo教程及注意点
- TortoiseSVN中分支和合并实践
- 用户空间与内核空间,进程上下文与中断上下文[总结]
- 格雷码(Gray code)简单 c 实现
- SQL查询初学者指南读书笔记(四)where从句
- Android FragmentActivity onActivityResult冲突问题
- mysql六:优化MySQL的21个建议,让MySQL跑的更快,更稳定
- 2015年第十三周杭电:母牛的故事
- node.js内存泄露问题记录
- Anker—学习成长笔记
- C++ 应用程序无法正常启动0xc000007b
- LeetCode 207-Course Schedule
- centos之php5.3升级到php5.4步骤