当前位置:   article > 正文

mysql 字段判断是否包含某个字符串_mysql 字段某包含某些值

mysql 字段某包含某些值

整体数据

SELECT id,learn_plan_id,sequence,is_valid,support_goods_level FROM qs_study_subject_plan_configuration WHERE is_valid=1 AND learn_plan_id=3;
  • 1

查询support_goods_level中包含1或者2的数据

FIND_IN_SET(str,strlist)

SELECT id,learn_plan_id,sequence,is_valid,support_goods_level FROM qs_study_subject_plan_configuration WHERE is_valid=1 AND learn_plan_id=3 AND FIND_IN_SET('1', support_goods_level);
  • 1
查询结果

LOCATE(substr,str)

SELECT id,learn_plan_id,sequence,is_valid,support_goods_level FROM qs_study_subject_plan_configuration WHERE is_valid=1 AND learn_plan_id=3 AND LOCATE('1',support_goods_level);
  • 1
查询结果

非期望情况


故,如果数据中有类似数据会查询不正确。

POSITION(substr IN str)

SELECT id,learn_plan_id,sequence,is_valid,support_goods_level FROM qs_study_subject_plan_configuration WHERE is_valid=1 AND learn_plan_id=3 AND POSITION('1' IN support_goods_level);
  • 1
查询结果

非期望情况


故,如果数据中有类似数据会查询不正确。

INSTR(str,substr)

SELECT id,learn_plan_id,sequence,is_valid,support_goods_level FROM qs_study_subject_plan_configuration WHERE is_valid=1 AND learn_plan_id=3 AND INSTR(support_goods_level,'1');
  • 1
查询结果

非期望情况

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/1011226
推荐阅读
相关标签
  

闽ICP备14008679号