第一部分 过滤数据 WHERE
2.1 WHERE 支持条件判断
1. 大于: >; 2. 小于: <; 3. 等于: =; 4. 大于等于: >=; 5. 小于等于: <=; 6. 不等于: !=; |
实例: 检测单个值, 可以将WHERE支持的条件判断语句替换;
> SELECT * FROM books WHERE book_id = 1; |
2.2 范围检测
> SELECT book_id, book_name FROM books WHERE book_id BETWEEN 3 AND 10; +---------+------------------+ | book_id | book_name | +---------+------------------+ | 3 | HTTP权威指南 | | 4 | 追风筝的人 | | 5 | 小王子 | | 6 | 围城 | | 7 | 活着 | | 8 | 解忧杂货店 | | 9 | 简爱 | | 10 | 平凡的世界 | +---------+------------------+ |
2.3 空值检测 NULL: 列 IS NULL;
> SELECT book_id, book_name FROM books WHERE description IS NULL; |
2.4 筛选 前后共同满足条件
+---------+------------------+------------------+------------------+-------------+----------+------+ | book_id | book_name | book_author_name | publication_date | description | classify | c | +---------+------------------+------------------+------------------+-------------+----------+------+ 16 | 国富论 | NULL | 2005-01-01 | NULL | 6 | NULL | | 17 | 伟大的博弈 | NULL | 2005-01-01 | NULL | 6 | NULL | > SELECT book_id, book_name FROM books WHERE book_id = 16 AND publication_date = '2005-01-01'; +---------+-----------+ | book_id | book_name | +---------+-----------+ | 16 | 国富论 | +---------+-----------+ 1 row in set (0.01 sec) |
2.5 筛选 OR 前后 满足一个条件即可
> SELECT book_id, book_name FROM books WHERE book_id = 16 OR publication_date = '2005-01-01'; +---------+-----------------+ | book_id | book_name | +---------+-----------------+ | 10 | 平凡的世界 | | 16 | 国富论 | | 17 | 伟大的博弈 | +---------+-----------------+ 3 rows in set (0.00 sec) |