【发布时间】:2017-02-10 06:16:56
【问题描述】:
这是我的屏幕截图,显示了使用命令 find_in_set 执行的查询。
它只执行特定行中的一组值。我想在单个查询中执行与find_in_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)
我在colors中选择了5和30,在days中选择了monday , friday,但它只显示1和3行。 p>
谁能纠正我的问题?
【问题讨论】:
-
你的截图在哪里?
-
改进格式,修正语法,添加标签
标签: mysql sql operator-precedence