0

I am trying to run a query that will search the bibliographic record database and output all of the records that have more than one 020 tag according to some set parameters.

Note: the parameters are flexible. The important part is to find the records with two or more 020 tags.

Here is what I have:

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

This will display each 020 and the accompanying text, but I want it to only display records with two or more 020s. Group by bib# maybe?

4

1 回答 1

0

我不确定您需要的确切语法,但您可以使用子查询:

                   select b.bib#
                   from bib b
                   where b.tag = '020'
                   group by b.bib#
                   HAVING COUNT(*) > 1

要识别具有多个“020”条目的 bib#,然后加入到该条目或使用 WHERE 条件与 IN 类似:

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.collection
于 2013-06-03T19:31:12.227 回答