concat 的用法

例如:

SELECT A.service_code, A.comm_code, A.service_kind, A.factory_code
FROM (


SELECT C . service_code , C . comm_code , C . service_kind , C . factory_code , C . auth
FROM tab_service_information C

) AS A
INNER JOIN tab_sys_machine_stat B ON ( A.comm_code = B.comm_code )
WHERE A.service_kind <>2
AND A.service_kind <>3
AND A.factory_code = '01'
AND (

concat ( '|' , A . auth , '|' ) LIKE '%|15|%'
OR concat ( '|' , A . auth , '|' ) LIKE '%|2|%'
OR concat ( '|' , A . auth , '|' ) LIKE '%|20|%'
OR concat ( '|' , A . auth , '|' ) LIKE '%|3|%'
OR concat ( '|' , A . auth , '|' ) LIKE '%|4|%'
OR concat ( '|' , A . auth , '|' ) LIKE '%|5|%'
OR concat ( '|' , A . auth , '|' ) LIKE '%|80|%'
OR concat ( '|' , A . auth , '|' ) LIKE '%|81|%'
OR concat ( '|' , A . auth , '|' ) LIKE '%|82|%'

)

如果数据库里面auth的值有1,11,2,22,222,在查询2的时候,会把2,22,222三个值同时查出来,这样就不对了

为了解决这个问题:concat( '|', A.auth, '|' )  在查询前,先将数据库表的字段auth的值加上竖线,然后再进行匹配 在视图的值就变成  |2|,|22|,|222|,在这基础上再LIKE ,

就能准确的查到2这个值了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值