青云山通过本文主要向大家介绍了mysql等相关知识,希望本文的分享对您有所帮助
- 使用场景:
一个工单号对应多个保单号,其数据库存储形式,如下:
编号 | 工单号 | 保单号 |
---|---|---|
1 | YY1860120171127005 | 8601,8602,8603 |
2 | YY1860120171127006 | 8601,8602 |
3 | YY1860120171127007 | 8601,8603 |
4 | YY1860120171127008 | 8604 |
- 需求:
根据保单号查询工单,例如,保单号为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);