- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是我的屏幕截图,显示了使用命令 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)
我在颜色中选择了5
和30
,在天中选择了星期一、星期五
> 但它只显示 1
和 3
行。
谁能解决我的问题吗?
最佳答案
请记住,在 bool 代数中,AND
的绑定(bind)比 OR
更紧密。
有一个default order of precedence of these operators .
当你写下这个:
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)
因此,您必须使用显式括号编写查询,以覆盖 AND
与 OR
的默认优先顺序。
该问题与使用 find_in_set() 无关。这只是一个 bool 代数错误。
关于mysql - 在mysql中执行find_in_set(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42152693/
尝试完成此查询,但行不通? SELECT cute_news.title, cute_news.id, cute_news.keywords, cute_fields.post_id, cute_fi
USE mysql; DROP PROCEDURE IF EXISTS ShowUsers; DELIMITER $ CREATE PROCEDURE `ShowUsers`(IN KnownUser
根据MySQL Reference Manual - The SET Type Normally, you search for SET values using the FIND_IN_SET()
这是我正在尝试做的事情: 名为“部门”的表与名为“员工”的表具有多对多关系。因此,表department_employees 包含列:department_id、employee_id、is_acti
我以前多次使用过FIND_IN_SET,但这次有点不同。 早些时候我在表中搜索单个值,例如 SELECT * FROM tbl_name where find_in_set('1212121212',
谁能帮我解决一个 mysql 问题?我有一行包含项目列表,例如:'1','2','3','4','5','6','7','8','9' .. 3 个元素的集合.. 从 3 到 3.. 现在我如何使用“
我有一个表,其中有一列名为 category,其中一行(我正在尝试查找)在该列中有一个值 '17,1,3'。我正在运行以下几个具有概述结果的查询: SELECT * FROM firms WHERE
直接去获取代码。 用户表 +----+------------------+ | id | username | +----+------------------+ | 1 | be
我在一个表中只有几个字段存储逗号分隔值。我可以使用 like 或 FIND_IN_SET 显示查询,以从逗号分隔值中查找数据。 MySQL query finding values in a comm
************提前谢谢******************** 我正在运行此查询: SELECT * FROM `test_lab_mapping` tlm WHERE FIND_IN_SE
我在使用 MySQL find_in_set() 函数时遇到了一个非常奇怪的问题。三张表,如下。底部的查询正在查找其职位在特定事件的 Activity_assoc 中列出的所有用户。换句话说:“哪些人
这个问题已经有答案了: MySQL find_in_set with multiple search string (7 个回答) 已关闭11 个月前。 我想从数据库字段中搜索多个值。以下是我的查询。
我有下表: ... | parents_id | ... ________________________ ... | 1, 40, 7 | ... ... | 10, 4, 7, 1
这个问题已经有答案了: MySQL find_in_set with multiple search string (7 个回答) 已关闭11 个月前。 我想从数据库字段中搜索多个值。以下是我的查询。
我有 2 张 table : 一个是具有“userid”列的用户,另一个是具有"is"和“否”列的意见。"is"和“否”列都包含逗号分隔值。 我想要的是计算“userid”出现在“yes”列中的次数以
我有一些数据,我认为 FIND_IN_SET 对我有用,但显然这是因为我正在寻找的是第一个元素。 即 SELECT * FROM myData WHERE FIND_IN_SET(2, field)>
我正在尝试将数组转换为查询字符串。也许你可以帮助我。 我的数组看起来像: Array ( [3] => Array ( [0] => 7
我有这些表 伊拉西表 invoice_nr | pard_suma | pard_vad | pirk_vad 1122 200 2,4,6 2,1,3 11
我有这个员工列表的 EMPLOYEE 表 +-----+---------------+-------------+ | ID |EMPLOYEE_ID | SKILLS | +--
我对 find_in_set 中的集合类型有一些疑问这是代码: create table set_test(id int,set_col SET('a','b','c','d')); insert i
我是一名优秀的程序员,十分优秀!