我有联系的数据如下:TSQL似与不似使用
Data
www.example.com/
www.example.com/someotherpath/
www.example.com/someotherpath/included
www.example.com/someexclusivepath/
www.example.com/someexclusivepath/AnyPathHereShouldBeExcluded/
www.example.com/someexclusivepath/AnyPathHereShouldBeExcluded
我试图写一个类似的条件应该只给我4个结果从上面:
www.example.com/
www.example.com/someotherpath/
www.example.com/someotherpath/included
www.example.com/someexclusivepath/
如果我做一个似与不似:
%www.example.com/%' AND Not like '%www.example.com/someexclusivepath/%'
这样就可以排除从上面的一些环节,以及其结果将是:
www.example.com/
www.example.com/someotherpath/
www.example.com/someotherpath/included
如何获得预期结果?
UPDATE:
例子:
DECLARE @tbl TABLE (link varchar(200))
INSERT INTO @tbl VALUES
('www.example.com/'),
('www.example.com/someotherpath/'),
('www.example.com/someotherpath/included'),
('www.example.com/someexclusivepath/'),('www.example.com/someexclusivepath/AnyPathHereShouldBeExcluded/'),
('www.example.com/someexclusivepath/AnyPathHereShouldBeExcluded')
SELECT * FROM @tbl
SELECT * FROM @tbl
WHERE link like '%www.example.com/%' AND Link Not like '%www.example.com/someexclusivepath/%'
如果我想用斜杠排除那个结尾,而不是用于'someexclusivepath'的结尾呢? –
我已更新示例以包含一个没有结尾的斜杠:( –
这是“someexlcusivepath”唯一的吗?如domain.com/abc?或者有多个如domain.com/abc1,domain.com/abc2 ? – Rooben