我正在尝试从我的数据库中获取具有垂直管道分隔值的数字的记录。
我有这样的查询:
SELECT * FROM level_3
WHERE
date_end = -6
AND
ccode = 'GB'
AND (
responsible LIKE '%5%' OR
accountable LIKE '%5%' OR
consulted LIKE '%5%' OR
informed LIKE '%5%'
)
以下是结果:
date_end ccode responsible accountable consulted informed
-6 GB |6| |6| |8|9|15| |8|
-6 GB |6|5| |6| |8| |16|
但 LIKE%5%匹配15但我只希望它与确切的数字匹配。我怎么能这样做呢?
答案 0 :(得分:3)
尝试此查询:
SELECT * FROM level_3
WHERE
date_end = -6
AND
ccode = 'GB'
AND (
responsible LIKE '%|5|%' OR
accountable LIKE '%|5|%' OR
consulted LIKE '%|5|%' OR
informed LIKE '%|5|%'
)
答案 1 :(得分:2)
LIKE有一个正则表达式挂件。
SELECT * FROM level_3
WHERE date_end = -6
AND ccode = 'GB'
AND (
responsible REGEXP '\|[0-9]+\|' OR
...
)
(备注用于其他用途:使用'^ ... $'
进行从开始^
到结束$
的总匹配。)
答案 2 :(得分:0)
您想要的是
Where concat('|',responsible,'|') like '%|5|%'