如何在 Sybase SQL 中将左连接与类似连接结合起来?

发布于 2024-11-04 16:22:07 字数 1284 浏览 0 评论 0原文

我一直在尝试在 Sybase 中将 likeleft 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南城追梦 2024-11-11 16:22:07

您应该使用 NOT EXISTS (就是这种情况):

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
where not exists (select null
                    from (
                             select '%o%'  expression union all
                             select '%i%'  expression
                         ) patterns
                   where numbers.name like patterns.expression)

You should use NOT EXISTS (it's the case):

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
where not exists (select null
                    from (
                             select '%o%'  expression union all
                             select '%i%'  expression
                         ) patterns
                   where numbers.name like patterns.expression)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文