1.使用where子句2.where子句操作符2.1 检查单个值2.2 不匹配检查2.3 范围值检查2.4 空值检查 使用where子句数据库表一般包含大量的数据,很少需要检
1.使用where子句
2.where子句操作符
2.1 检查单个值
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)
提示:在同时使用order by 和 where子句时,应该让order by位于where之后。
2.1 检查单个值
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)
--结束END--
本文标题: MySQL必知必会---过滤数据
本文链接: https://www.lsjlt.com/news/45590.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-03
2024-05-03
2024-05-03
2024-05-03
2024-05-03
2024-05-03
2024-05-03
2024-05-03
2024-05-03
2024-05-03
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0