0

尝试返回同时存在于 MOF 和 SIL 位置的标题列表(t.processed),然后从该列表中减去 SIL 中存在的标题

修改:

select t.processed, i.call
from item i, title t
where i.bib# = t.bib#
    and i.collection = 'PIC'
    and i.location in ('MOF', 'SIL')
except
select t.processed, i.call
from item i, title t
where i.bib# = t.bib#
    and i.collection = 'PIC'
    and i.location = 'SIL'

不幸的是,这没有返回任何结果,但它更接近我所需要的

示例输出相当简单(且灵活):

processed        call
Mouse count      P WAL
Fly away home    P BUN

进一步澄清:我想找到在 SIL 和 MOF 位置重复的标题(例如 Fly away home),然后从该列表中删除出现在 SIL 位置的标题

4

4 回答 4

1

假设 Item 类似于

ID Item Collection Location
1  1    PIC        MOF
2  1    PIC        SIL
3  2    PIC        MOF
4  3    PIC        SIL

然后

Select select mof.item#, mof.call, mof.collection From Item mof
Left Join Item sil On mof.Item# = sil.Item# and sil.Collection = mof.Collection
Where sil.Location = 'SIL'
and mof.Location = 'MOF'
and mof.Collection = 'PIC'
and sil.ID is null

会让你靠近。停止使用旧的连接语法...

于 2013-06-05T16:11:16.933 回答
0

EXCEPT运算符执行此操作,至少对于某些 SQL 风格:

select i.item#, t.processed, i.call, i.collection
from item i, title t
where i.bib# = t.bib#
    and i.collection = 'PIC'
    and i.location = 'MOF'
except
select i.item#, t.processed, i.call, i.collection
from item i, title t
where i.bib# = t.bib#
    and i.collection = 'PIC'
    and i.location = 'SIL'
于 2013-06-05T15:52:30.717 回答
0

尝试

select i.item#, t.processed, i.call, i.collection
from item i, title t
where i.bib# = t.bib#
    and (
         (i.collection = 'PIC' and i.location <> 'SIL') 
         or ( i.collection = 'PIC' and  i.location = 'MOF')
        )
于 2013-06-05T15:53:03.843 回答
0

最终编辑:

这将是我正在寻找的查询(我很抱歉没有充分解释自己)

select t.processed
from title t, item i
where t.bib# = i.bib#
and i.location = 'MOF'
and i.collection = 'PIC'
and i.bib# not in (select bib# from item where location = 'SIL' and collection = 'PIC')

我仍然无法解决子查询。我的麻烦在于没有使用主键i.bib#作为子查询的基础。

谢谢大家的建议!

于 2013-06-06T15:02:38.350 回答