- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
根据MySQL Reference Manual - The SET Type
Normally, you search for SET values using the FIND_IN_SET() function or the LIKE operator:
mysql> SELECT * FROM tbl_name WHERE FIND_IN_SET('value',set_col)>0;
FIND_IN_SET(str,strlist)
Returns a value in the range of 1 to N if the string str is in the string list strlist consisting of N substrings. A string list is a string composed of substrings separated by “,” characters. If the first argument is a constant string and the second is a column of type SET, the FIND_IN_SET() function is optimized to use bit arithmetic. Returns 0 if str is not in strlist or if strlist is the empty string. Returns NULL if either argument is NULL.
因此,我认为
SELECT * FROM tbl_name WHERE FIND_IN_SET('value',set_col)
当您想从集合中查找值时可以正常工作。
那么为什么 MySQL 引用手册中的示例显式地与 >0
进行比较?
有什么不同吗?
最佳答案
考虑以下两个 WHERE
子句:
WHERE FIND_IN_SET('value', set_col) > 0
WHERE FIND_IN_SET('value', set_col)
在第一个中,如果 sel_col
中的任何条目包含value
,则 FIND_IN_SET() 的返回值
将为某个大于 0 的数字,否则为 0。换句话说,如果找到 value
,则返回 TRUE
,并且 否则为 FALSE
。
第二个 WHERE
子句将计算为 WHERE X
,其中 X
为 1 或更大,如果 value
被发现,或者 0,如果 value
没有找到。在MySQL中,值0
与FALSE
同义,1
或更大的正数与TRUE
同义>(参见documentation)。
因此这两个 WHERE
子句的行为相同。
关于mysql - WHERE FIND_IN_SET(...)>0 和 WHERE FIND_IN_SET(...) 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37849470/
尝试完成此查询,但行不通? 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
我是一名优秀的程序员,十分优秀!