![84fe4681c35810202bbf791e2b1939c4.png](https://img-blog.csdnimg.cn/img_convert/84fe4681c35810202bbf791e2b1939c4.png)
WHERE 子句用筛选满足某些条件的数据。
SQL WHERE 语法
按照某种条件地从表中选取数据,可将 WHERE 子句添加到 SELECT 语句中。
![ee2482d1c9c0b1a29cc132d1b673e15d.png](https://img-blog.csdnimg.cn/img_convert/ee2482d1c9c0b1a29cc132d1b673e15d.png)
可用于WHERE字句的运算符,大致如下:
![fbca516aae3518d04f9aafcffd6b8115.png](https://img-blog.csdnimg.cn/img_convert/fbca516aae3518d04f9aafcffd6b8115.png)
演示数据库
![079fa893f6caa8a13a2e29ab0206f487.png](https://img-blog.csdnimg.cn/img_convert/079fa893f6caa8a13a2e29ab0206f487.png)
WHERE 实例
现在,我们希望从Students_hobby_t表中获取Age字段值大于15的学生数据:
![6c6b2fb8abc9564c82527fdf8da874a8.png](https://img-blog.csdnimg.cn/img_convert/6c6b2fb8abc9564c82527fdf8da874a8.png)
输出结果为:
![eeae6aed312473002a43bae6106836f4.png](https://img-blog.csdnimg.cn/img_convert/eeae6aed312473002a43bae6106836f4.png)
多个WHERE 子句逻辑运算实例
And(与关系):同时满足两个条件的值。
我们希望从Students_hobby_t表中获取Age字段值大于15,同时Hobby_id 等于12 的学生数据,如下:
![f405ba95ea6901d664252b7df7487b08.png](https://img-blog.csdnimg.cn/img_convert/f405ba95ea6901d664252b7df7487b08.png)
Or(或关系):满足其中一个条件的值
我们希望从Students_hobby_t表中获取Age字段值大于15,或者Hobby_id 等于12 的学生数据,如下:
![fc029b5fcc0e1a8fd04d9b7c18353d2f.png](https://img-blog.csdnimg.cn/img_convert/fc029b5fcc0e1a8fd04d9b7c18353d2f.png)
Not(非关系):满足不包含该条件的值。
我们希望从Students_hobby_t表中获取Age字段值大于15,或者Hobby_id 不等于12 的学生数据,如下:
![6833dd72fa2041f70e4f4b4f99b3f09c.png](https://img-blog.csdnimg.cn/img_convert/6833dd72fa2041f70e4f4b4f99b3f09c.png)
逻辑运算的优先级如下:
![816018a2a254cbe0d49bc2c492471498.png](https://img-blog.csdnimg.cn/img_convert/816018a2a254cbe0d49bc2c492471498.png)