我正在尝试运行一个查询,该查询将搜索书目记录数据库,并根据一些设置的参数输出具有一个以上020标签的所有记录。
注意:参数是灵活的。重要的部分是找到具有两个或更多020标签的记录。
这就是我所拥有的:
select b.bib#, b.text, t.processed, i.call, i.collection, i.creation_date
from bib b, title t, item i
where b.bib# = t.bib# and t.bib# = i.bib#
and b.tag = '020'
and i.collection in ('PIC', 'E')
order by i.creation_date DESC, i.collection这将显示每个020和伴随的文本,但我希望它只显示具有两个或更多020的记录。也许是按bib#分组的?
发布于 2013-06-04 03:31:12
我不确定您需要的确切语法,但您可以使用子查询:
select b.bib#
from bib b
where b.tag = '020'
group by b.bib#
HAVING COUNT(*) > 1要识别具有多个'020‘条目的bib#,请加入该条目或将WHERE条件与IN like一起使用:
select b.bib#, b.text, t.processed, i.call, i.collection, i.creation_date
from bib b, title t, item i
where b.bib# = t.bib# and t.bib# = i.bib#
and b.tag = '020'
and i.collection in ('PIC', 'E')
and b.bib# IN (select b.bib#
from bib b
where b.tag = '020'
group by b.bib#
HAVING COUNT(*) > 1)
order by i.creation_date DESC, i.collectionhttps://stackoverflow.com/questions/16904267
复制相似问题