溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶(hù)服務(wù)條款》

MySQL必知必會(huì)---過(guò)濾數(shù)據(jù)

發(fā)布時(shí)間:2020-08-06 10:00:33 來(lái)源:網(wǎng)絡(luò) 閱讀:593 作者:蝸牛的嘲諷 欄目:MySQL數(shù)據(jù)庫(kù)

1.使用where子句
2.where子句操作符
2.1 檢查單個(gè)值
2.2 不匹配檢查
2.3 范圍值檢查
2.4 空值檢查

  1. 使用where子句
    數(shù)據(jù)庫(kù)表一般包含大量的數(shù)據(jù),很少需要檢索表中的所有行。通常會(huì)根據(jù)特定操作或報(bào)告的需要提取表數(shù)據(jù)的子集。

例如:查找年齡等于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之后。

  1. where子句操作符
    等于、不等于、小于、小于等于、大于、大于等于、在指定的兩個(gè)值之間使用between

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)

向AI問(wèn)一下細(xì)節(jié)

免責(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)容。

AI