本文共 1527 字,大约阅读时间需要 5 分钟。
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)转载于:https://blog.51cto.com/imork/2119177