dqm4675 2017-03-11 15:28
浏览 140
已采纳

如何从表字段MySQL中的字符串中获取部分精确值

I got table promos, with field store_id_list (VARCHAR). what i want to achieve here is i want this promo can be available into multiple store in 1 record, instead using multiple record, the store_id_list value is the list of store_id separated by comma (ex: 1,4,5,7,)

Now, i want to get record of table promo, where i have single store_id value, ex: store_id=5 how can i do that in MySQL? can i do that in single query? if using LIKE then more likely i can get 15 or 45 instead of 5.

  • 写回答

2条回答 默认 最新

  • dounuo8797 2017-03-11 15:34
    关注

    My advice is to normalize your tables, and have a db-record per store/promo. But it can be done like this:

    Make sure you have commas at the beginning and end of the column value, like this:

    store_id_list : ,1,4,5,7,
    

    And then query like this:

    ... where store_id_list like '%,5,%'
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?