mysql必知必會 (三)過濾數據(where子句指定搜索條件)

相等測試

mysql> select prod_name,prod_price
    -> from products
    -> where prod_price = 3.49;
+---------------------+------------+
| prod_name           | prod_price |
+---------------------+------------+
| Fish bean bag toy   |       3.49 |
| Bird bean bag toy   |       3.49 |
| Rabbit bean bag toy |       3.49 |
+---------------------+------------+
3 rows in set (0.00 sec)

在這裏插入圖片描述

where子句操作符

在這裏插入圖片描述

mysql> select prod_name, prod_price
    -> from products
    -> where prod_name = 'fuses';
Empty set (0.00 sec)

注意相等測試不是用==,就用賦值符號,這和其他語言都不一樣

不匹配測試

mysql> select prod_name, prod_price
    -> from products
    -> where prod_name <> 'fuses';
+---------------------+------------+
| prod_name           | prod_price |
+---------------------+------------+
| Fish bean bag toy   |       3.49 |
| Bird bean bag toy   |       3.49 |
| Rabbit bean bag toy |       3.49 |
| 8 inch teddy bear   |       5.99 |
| 12 inch teddy bear  |       8.99 |
| 18 inch teddy bear  |      11.99 |
| Raggedy Ann         |       4.99 |
| King doll           |       9.49 |
| Queen doll          |       9.49 |
+---------------------+------------+
9 rows in set (0.00 sec)

範圍值檢查

mysql> select prod_name, prod_price
    -> from products
    -> where prod_price between 3 and 8;
+---------------------+------------+
| prod_name           | prod_price |
+---------------------+------------+
| Fish bean bag toy   |       3.49 |
| Bird bean bag toy   |       3.49 |
| Rabbit bean bag toy |       3.49 |
| 8 inch teddy bear   |       5.99 |
| Raggedy Ann         |       4.99 |
+---------------------+------------+
5 rows in set (0.00 sec)

空值檢查

mysql> select prod_name, prod_price
    -> from products
    -> where prod_price is null;
Empty set (0.00 sec)

總結

  • order by子句必須在where子句之後
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章