mysql |来自空列和FIND_IN_SET的请求 [英] mysql | Request from empty column and FIND_IN_SET

查看:102
本文介绍了mysql |来自空列和FIND_IN_SET的请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张桌子:

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的请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆