括号()的作用
括号()的作用,先执行括号里面的命令,提高优先级
括号里面有"与"和"或"时,"与"优先。
and 与 (2者都要满足)
or 或 (满足其一即可)
mysql> select name,uid,gid from user
-> where name="bin";
+------+------+------+
| name | uid | gid |
+------+------+------+
| bin | 2 | 0 |
+------+------+------+
mysql> select name,(uid+gid)/2 as pjz from user where name="bin";
+------+--------+
| name | pjz |
+------+--------+
| bin | 1.0000 |
+------+--------+
mysql> select name,uid,gid,(uid+gid)/2 as pjz from user where name="bin";
+------+------+------+--------+
| name | uid | gid | pjz |
+------+------+------+--------+
| bin | 2 | 0 | 1.0000 |
+------+------+------+--------+
mysql> select name,uid from user
-> where
-> name="root" and id=1 or uid=2; 先找到name=root并且id=1的记录,然后再找到或者uid=2的记录
+------+------+
| name | uid |
+------+------+
| root | 1 |
| bin | 2 |
+------+------+
mysql> select name,uid from user where name="root" and (id=1 or uid=2); 先找到id=1或者uid=2的记录,然后再从找到的结果里,找到同时满足name=root的记录
+------+------+
| name | uid |
+------+------+
| root | 1 |
+------+------+