dongqiang2069 2014-03-18 13:10
浏览 23
已采纳

mysql | 从空列和FIND_IN_SET请求

I have a table:

id  name   position   status
1   A      1,2        1
2   B      1          1
3   C                 1
4   D      2          1

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` ) 

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.

  • 写回答

1条回答 默认 最新

  • drkxgs9358 2014-03-18 13:19
    关注

    you dont need to check if position is empty while you checking numbers in field list .

    you dont need to check position = FIND_IN_SET.... . it will return the value where 1 is in position.

    you need to do it like that:

     SELECT `id` 
     FROM  `table` 
     WHERE `status`=1
     AND  FIND_IN_SET( 1,  `position` ) 
     OR   FIND_IN_SET( 2,  `position` ) 
    

    DEMO HERE

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥15 复杂网络,变滞后传递熵,FDA
  • ¥20 csv格式数据集预处理及模型选择
  • ¥15 部分网页页面无法显示!
  • ¥15 怎样解决power bi 中设置管理聚合,详细信息表和详细信息列显示灰色,而不能选择相应的内容呢?
  • ¥15 QTOF MSE数据分析
  • ¥15 平板录音机录音问题解决