gpt4 book ai didi

mysql - WHERE FIND_IN_SET(...)>0 和 WHERE FIND_IN_SET(...) 之间的区别

转载 作者:行者123 更新时间:2023-11-29 11:28:11 25 4
gpt4 key购买 nike

根据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;

根据MySQL Reference Manual

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中,值0FALSE同义,1或更大的正数与TRUE同义>(参见documentation)。

因此这两个 WHERE 子句的行为相同。

关于mysql - WHERE FIND_IN_SET(...)>0 和 WHERE FIND_IN_SET(...) 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37849470/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com