嗨,我有一个表结构:
mysql>DESC file;
file_id
fullpathname
有记录
file_id | fullpathname
--------+------------------------------------------------------
6 | /var/tmp/4x4 and 6x4/test/test3.txt
7 | /var/tmp/4x4 and 6x4/test/somefile
8 | /var/tmp/4x4 and 6x4/test
9 | /var/tmp/4x4 and 6x4/6x4_1.JPG
10 | /var/tmp/4x4 and 6x4/6x4_2.JPG
11 | /var/tmp/4x4 and 6x4/4x4_2.jpg
12 | /var/tmp/4x4 and 6x4/4x4_1.jpg
13 | /var/tmp/dir/4x4 and 6x4
并且查询需要与我下面的查询差不多(但它不起作用)
SELECT * FROM file
WHERE fullpathname LIKE '/var/tmp/4x4 and 6x4%'
AND fullpathname NOT LIKE '/var/tmp/4x4 and 6x4/%/'
但它不需要返回 file_id 6 和 7,它只需要选择一个节点深度的“路径”。这很奇怪,但情况就是这样
它应该返回的是
file_id | fullpathname
--------+------------------------------------------------------
8 | /var/tmp/4x4 and 6x4/test
9 | /var/tmp/4x4 and 6x4/6x4_1.JPG
10 | /var/tmp/4x4 and 6x4/6x4_2.JPG
11 | /var/tmp/4x4 and 6x4/4x4_2.jpg
12 | /var/tmp/4x4 and 6x4/4x4_1.jpg
13 | /var/tmp/dir/4x4 and 6x4
最佳答案
试试这个:
SELECT * FROM file
WHERE fullpathname LIKE '/var/tmp/4x4 and 6x4%'
AND fullpathname NOT LIKE '/var/tmp/4x4 and 6x4/%/%'
关于mysql - where 子句难题 : where "LIKE" one thing but not "LIKE another" is failing?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13493529/