在mysql的_set()中执行find_
这是我的屏幕截图,显示了使用命令在mysql的_set()中执行find_,mysql,sql,operator-precedence,Mysql,Sql,Operator Precedence,这是我的屏幕截图,显示了使用命令find\u in\u set执行的查询 它只执行特定行中的一组值。我希望在单个查询中执行表中与find\u in\u set命令匹配的所有值 看看我的代码: select * from shirts; +----+--------------+------------------------------------+ | id | colors | days | +----+--------
find\u in\u set
执行的查询
它只执行特定行中的一组值。我希望在单个查询中执行表中与find\u in\u set
命令匹配的所有值
看看我的代码:
select * from shirts;
+----+--------------+------------------------------------+
| id | colors | days |
+----+--------------+------------------------------------+
| 1 | 1,2,5,12,15 | monday, friday, thursday |
| 2 | 1,5,12,15,30 | tuesday,monday |
| 3 | 2,5,11,15,28 | monday, friday,wednesday ,thursday |
| 4 | 1,2,7,12,15 | tuesday,monday |
| 5 | 2,4,8,12,15 | tuesday,monday |
+----+--------------+------------------------------------+
5 rows in set (0.00 sec)
mysql> select * from shirts where find_in_set('5',colors) or find_in_set('30',colors) or find_in_set('30', colors) and find_in_set('monday',days) or find_in_set('tuesday',days);
+----+--------------+------------------------------------+
| id | colors | days |
+----+--------------+------------------------------------+
| 1 | 1,2,5,12,15 | monday, friday, thursday |
| 2 | 1,5,12,15,30 | tuesday,monday |
| 3 | 2,5,11,15,28 | monday, friday,wednesday ,thursday |
| 4 | 1,2,7,12,15 | tuesday,monday |
| 5 | 2,4,8,12,15 | tuesday,monday |
+----+--------------+------------------------------------+
5 rows in set (0.00 sec)
mysql> select * from shirts where find_in_set('5',colors) or find_in_set('30',colors) and find_in_set('monday',days) or find_in_set('tuesday',days);
+----+--------------+------------------------------------+
| id | colors | days |
+----+--------------+------------------------------------+
| 1 | 1,2,5,12,15 | monday, friday, thursday |
| 2 | 1,5,12,15,30 | tuesday,monday |
| 3 | 2,5,11,15,28 | monday, friday,wednesday ,thursday |
| 4 | 1,2,7,12,15 | tuesday,monday |
| 5 | 2,4,8,12,15 | tuesday,monday |
+----+--------------+------------------------------------+
5 rows in set (0.00 sec)
我选择了5
和30
的颜色和周一、周五
的天,但它只显示1
和3
行
有人能纠正我的问题吗?请记住,在布尔代数中,
和
的绑定比或
更紧密
有一个问题
当你写这篇文章时:
select * from shirts where A or B and C or D
总是像这样使用括号:
select * from shirts where A or (B and C) or D
select * from shirts where (A or B) and (C or D)
但你想让它像这样:
select * from shirts where A or (B and C) or D
select * from shirts where (A or B) and (C or D)
因此,您必须使用显式括号编写查询,以覆盖和
与或
的默认优先顺序
这个问题与在_set()中使用find_无关。这只是一个布尔代数错误。你的截图在哪里?改进了格式,修正了语法,添加了标记