第一部分 過濾數據 WHEREcode
2.1 WHERE 支持條件判斷blog
1. 大於: >;ip 2. 小於: <;get 3. 等於: =;io 4. 大於等於: >=;table 5. 小於等於: <=;class 6. 不等於: !=;date |
實例: 檢測單個值, 能夠將WHERE支持的條件判斷語句替換;im
> SELECT * FROM books WHERE book_id = 1;數據 |
2.2 範圍檢測BETWEEN AND
> 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 篩選 AND 先後共同知足條件
+---------+------------------+------------------+------------------+-------------+----------+------+ | 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) |