如何在 Sybase SQL 中将左连接与类似连接结合起来?
我一直在尝试在 Sybase 中将 like
与 left join 结合起来。
例如(尽管在我的例子中有点复杂),我正在寻找既不包含 o
也不包含 i
的文本。
我可以做相反的事情,即包含这些字母的文本:
select numbers.name from
(
select 'one' name union all
select 'two' name union all
select 'three' name union all -- neither %o% nor %i%
select 'four' name union all
select 'five' name union all
select 'six' name union all
select 'seven' name union all -- neither %o% nor %i%
select 'eight' name union all
select 'nine' name union all
select 'ten' name -- neither %o% nor %i%
) numbers,
(
select '%o%' expression union all
select '%i%' expression
) patterns
where
numbers.name like patterns.expression
按预期选择除 三
、七
和 十
之外的所有记录。
现在,我正在寻找一种方法来查找这三个记录。我考虑过将数字与模式连接起来,然后过滤为空的表达式。像这样的事情:
numbers.name *like patterns.expression and
patterns.expression is null
显然,这是行不通的。因此,我很高兴收到任何指向正确方向的指示。
就其价值而言,这是我正在开发的版本:
select @@version
'Adaptive Server Enterprise/15.0.3/EBF 17156 ESD#3/P/Sun_svr4/OS 5.8/ase1503/2726/64-bit/FBO/Fri Feb 5 05:26:23 2010'
I am stuck trying to combine a like
with a left join in Sybase.
For example (although in my case it's a bit more complicated), I am looking for text that neither contains an o
nor an i
.
I am able to do the opposite, that is, text containing either of these letters:
select numbers.name from
(
select 'one' name union all
select 'two' name union all
select 'three' name union all -- neither %o% nor %i%
select 'four' name union all
select 'five' name union all
select 'six' name union all
select 'seven' name union all -- neither %o% nor %i%
select 'eight' name union all
select 'nine' name union all
select 'ten' name -- neither %o% nor %i%
) numbers,
(
select '%o%' expression union all
select '%i%' expression
) patterns
where
numbers.name like patterns.expression
selects all records except three
, seven
and ten
as expected.
Now, I am looking for a way to find these three records. I thought about left joining numbers with patterns and then filtering on the expression being null. Something like this:
numbers.name *like patterns.expression and
patterns.expression is null
Obviously, this doesn't work. So, I'd be happy for any pointer given into the right direction.
For what's its worth, this is the version I am working on:
select @@version
'Adaptive Server Enterprise/15.0.3/EBF 17156 ESD#3/P/Sun_svr4/OS 5.8/ase1503/2726/64-bit/FBO/Fri Feb 5 05:26:23 2010'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该使用
NOT EXISTS
(就是这种情况):You should use
NOT EXISTS
(it's the case):