我有一张桌子:
id name position status
1 A 1,2 1
2 B 1 1
3 C 1
4 D 2 1
其中:position
列是一个文本字段;我的请求在这里:
Where: position
column is a text field;
My request is here:
SELECT `id`
FROM `table`
WHERE `status`=1
AND `position` > ''
AND `position` = FIND_IN_SET( 1, `position` )
OR `position` = FIND_IN_SET( 2, `position` )
此请求将返回:1,2,3,4.这是我需要的错误:1,2,4 ->条件:(position
> '').哪里有问题以及如何更改我的请求?谢谢.
This request will return: 1,2,3,4. This is a wrong as I need: 1,2,4 ->
Condition: (position
> '').
Where is a problem and how to change my request?
Thanks.
您在检查字段列表中的数字时无需检查位置是否为空.
you dont need to check if position is empty while you checking numbers in field list .
你不需要检查 position = FIND_IN_SET....
.它将返回 1 所在位置的值.
you dont need to check position = FIND_IN_SET....
. it will return the value where 1 is in position.
你需要这样做:
SELECT `id`
FROM `table`
WHERE `status`=1
AND FIND_IN_SET( 1, `position` )
OR FIND_IN_SET( 2, `position` )
此处演示
这篇关于mysql |来自空列和 FIND_IN_SET 的请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!