文章目錄
相等測試
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子句之後