简体   繁体   中英

SQL: Select rows with a column value that occurs at least two times?

Here is the database I'm using: https://ufile.io/72wph

The relational schema for the Academics database is as follows:

DEPARTMENT( deptnum , descrip, instname, deptname, state, postcode)

ACADEMIC( acnum , deptnum*, famname, givename, initials, title)

PAPER( panum , title)

AUTHOR( panum*, acnum* )

FIELD( fieldnum , id, title)

INTEREST( fieldnum*, acnum* , descrip)

Some notes on the Academics database:

● An academic department belongs to one institution ( instname ) and often has many academics. An academic only works for one department.

● Research papers ( PAPER ) are often authored by several academics, and of course an academic often writes several papers ( AUTHOR ).

● A research field ( FIELD ) often attracts many academics and an academic can have interest ( INTEREST ) in several research fields.

With this information I have to list the PANUM of papers having at least two authors.

I'm not sure whether I should be joining the AUTHOR table with the ACADEMIC table, or is there a way to do it with just the AUTHOR table?

Unless I'm missing something, I think you can answer your question with a single query on the AUTHOR table alone:

SELECT panum
FROM AUTHOR
GROUP BY panum
HAVING COUNT(*) >= 2;

Joining to the academic table is not needed, because that table just contains metadata for each author, but has nothing to do with the papers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM