dongnuo6310 2014-08-26 11:17
浏览 88
已采纳

如何从mysql中删除具有给定id的记录

Now i have the table like

--------------------------
merge_id  |  merge_combo |
--------------------------
A1        |   25,9       |
A2        |   25,21      |
A3        |   2,5,15     |
A4        |   2,9,5      |
A5        |   12,19,2    |
A6        |   2,1        |
--------------------------

for example now if i pass the value 9, then it should check the merge_combo and delete the rows which are having 9 (A1,A4 this two having 9)

  • 写回答

8条回答 默认 最新

  • douciwang6819 2014-08-26 11:24
    关注

    You can do this with find_in_set():

    delete from tbl
        where find_in_set(9, merge_combo) > 0;
    

    The bigger issue is that you are storing numbers in a string for a list. SQL has this great data structure for storing lists -- it is called a table. In this case, you want a junction table, with one row per merge_id and combo item.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(7条)

报告相同问题?

悬赏问题

  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办