您好,登錄后才能下訂單哦!
1.使用where子句
2.where子句操作符
2.1 檢查單個(gè)值
2.2 不匹配檢查
2.3 范圍值檢查
2.4 空值檢查
例如:查找年齡等于22歲的行
MariaDB [test]> select age
-> from user
-> where age=22;
+------+
| age |
+------+
| 22 |
+------+
1 row in set (0.00 sec)
提示:在同時(shí)使用order by 和 where子句時(shí),應(yīng)該讓order by位于where之后。
2.1 檢查單個(gè)值
MariaDB [test]> select id,age,province
-> from user
-> where province = '北京';
+----+------+----------+
| id | age | province |
+----+------+----------+
| 1 | 22 | 北京 |
| 4 | 14 | 北京 |
| 7 | 45 | 北京 |
| 11 | 29 | 北京 |
| 13 | 24 | 北京 |
+----+------+----------+
5 rows in set (0.01 sec)
2.2 不匹配檢查
MariaDB [test]> select id, age, province
-> from user
-> where age <> 22;
+----+------+----------+
| id | age | province |
+----+------+----------+
| 2 | 25 | 廣東 |
| 3 | 56 | 天津 |
| 4 | 14 | 北京 |
| 5 | 36 | 廣東 |
| 6 | 68 | 湖南 |
| 7 | 45 | 北京 |
| 8 | 17 | 河北 |
| 9 | 33 | 天津 |
| 10 | 27 | 湖南 |
| 11 | 29 | 北京 |
| 12 | 70 | 廣東 |
| 13 | 24 | 北京 |
+----+------+----------+
12 rows in set (0.00 sec)
2.3 范圍值檢查
MariaDB [test]> select id,age,province
-> from user
-> where age between 25 and 33;
+----+------+----------+
| id | age | province |
+----+------+----------+
| 2 | 25 | 廣東 |
| 9 | 33 | 天津 |
| 10 | 27 | 湖南 |
| 11 | 29 | 北京 |
+----+------+----------+
4 rows in set (0.00 sec)
2.4 空值檢查
提示:空值NULL(no value)與0、空字符串或空格不同。
MariaDB [test]> select id,age,province
-> from user
-> where age IS NULL;
Empty set (0.00 sec)
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。