页次: 1
筛选的方式有
where 条件 ;筛选指定的条件
where and ; 满足多个条件, 可以有 多个and
where or ; 满足条件之一,即可
where and or ; 用于构造复杂的逻辑, 这里 and , or 和一般的语言一样, and 的优先级高
where in ; 在指定的范围
where not ; 取反的意思
--------------
示例:
先填写表
mysql> select * from tb001; +------+------+------+--------+ | type | name | age | weight | +------+------+------+--------+ | 1 | x1 | 1 | 1.1 | | 1 | x2 | 2 | 2.2 | | 2 | x1 | 1 | 3 | | 2 | x3 | 2 | 3 | | 3 | x3 | 3 | 4 | +------+------+------+--------+ 5 rows in set (0.00 sec)
ipbbs.net
离线
mysql> select * from tb001 where type=1; +------+------+------+--------+ | type | name | age | weight | +------+------+------+--------+ | 1 | x1 | 1 | 1.1 | | 1 | x2 | 2 | 2.2 | +------+------+------+--------+ 2 rows in set (0.00 sec) mysql> select * from tb001 where type=1 and age=2; +------+------+------+--------+ | type | name | age | weight | +------+------+------+--------+ | 1 | x2 | 2 | 2.2 | +------+------+------+--------+ 1 row in set (0.00 sec) mysql> select * from tb001 where type=1 or type=3; +------+------+------+--------+ | type | name | age | weight | +------+------+------+--------+ | 1 | x1 | 1 | 1.1 | | 1 | x2 | 2 | 2.2 | | 3 | x3 | 3 | 4 | +------+------+------+--------+ 3 rows in set (0.00 sec) mysql> select * from tb001 where type=1 or type =3; +------+------+------+--------+ | type | name | age | weight | +------+------+------+--------+ | 1 | x1 | 1 | 1.1 | | 1 | x2 | 2 | 2.2 | | 3 | x3 | 3 | 4 | +------+------+------+--------+ 3 rows in set (0.00 sec) mysql> select * from tb001 where type=1 or type =3 and type =1; +------+------+------+--------+ | type | name | age | weight | +------+------+------+--------+ | 1 | x1 | 1 | 1.1 | | 1 | x2 | 2 | 2.2 | +------+------+------+--------+ 2 rows in set (0.00 sec) mysql> select * from tb001 where type=1 or (type =3 and type =1); +------+------+------+--------+ | type | name | age | weight | +------+------+------+--------+ | 1 | x1 | 1 | 1.1 | | 1 | x2 | 2 | 2.2 | +------+------+------+--------+ 2 rows in set (0.02 sec) mysql> select * from tb001 where type=1 and type =3 and type =1; Empty set (0.00 sec) mysql> select * from tb001 where type=1 and type =3 or type =1; +------+------+------+--------+ | type | name | age | weight | +------+------+------+--------+ | 1 | x1 | 1 | 1.1 | | 1 | x2 | 2 | 2.2 | +------+------+------+--------+ 2 rows in set (0.00 sec) mysql> select * from tb001 where age in (2, 3); +------+------+------+--------+ | type | name | age | weight | +------+------+------+--------+ | 1 | x2 | 2 | 2.2 | | 2 | x3 | 2 | 3 | | 3 | x3 | 3 | 4 | +------+------+------+--------+ 3 rows in set (0.00 sec) mysql> select * from tb001 where age not in (2, 3); +------+------+------+--------+ | type | name | age | weight | +------+------+------+--------+ | 1 | x1 | 1 | 1.1 | | 2 | x1 | 1 | 3 | +------+------+------+--------+ 2 rows in set (0.00 sec)
ipbbs.net
离线
页次: 1