您的位置:首页 > 数据库 > MySQL

MySQL中特定格式的字符串部分完全匹配查询

2017-11-28 14:17 465 查看
转载:MySQL字符串操作

- 使用场景:

一个工单号对应多个保单号,其数据库存储形式,如下:

编号工单号保单号
1YY18601201711270058601,8602,8603
2YY18601201711270068601,8602
3YY18601201711270078601,8603
4YY18601201711270088604
需求:

根据保单号查询工单,例如,保单号为8601时,显示3条数据;保单号为8602,显示1和2;保单为8604时,只显示4

SQL:

使用find_in_set(str,str1)函数

select * from t_order where find_in_set('8601',cont_no);
select * from t_order where find_in_set('8602,cont_no);
select * from t_order where find_in_set('8604,cont_no);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mysql
相关文章推荐