2021-04-07
                                阅读量:
                                1005
                            
                        SQL怎么用列和另一列匹配,但是是模糊匹配?
                        问:
SQL怎么用列和另一列匹配,但是是模糊匹配?
答:
将两表进行连接后在where子句中使用模糊匹配,例如A表中的proj_dept字段包含了多个B表中的,用逗号分隔的dept_id,如果要实现A表和B表的关联可以执行以下代码:
select * from A,B
where concat(',',A.proj_dept,',') like concat('%,',cast(B.dept_id as char),',%')
order by proj_dept,dept_id;
 240.0000
                                240.0000
                             1
                                1
                             0
                                0
                             
                                
                             关注作者
                                关注作者
                             收藏
                                    收藏
                                                            评论(0)
                    
 发表评论
发表评论
暂无数据
                        
                        推荐帖子
                    
                0条评论
                        0条评论
                        0条评论
                         
             
                 
                 
                            

 
                             
                             
                             
                             
                             
                             
                                    