0

嗨,我有一个表结构:

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             
4

1 回答 1

1

试试这个:

SELECT * FROM file
WHERE fullpathname LIKE '/var/tmp/4x4 and 6x4%'
AND fullpathname NOT LIKE '/var/tmp/4x4 and 6x4/%/%'
于 2012-11-21T12:45:49.327 回答