1

我有 2 张桌子。一个叫artist. 这是表结构:

artistID lastname firstname nationality dateofbirth datedcease

另一个表称为work

workId title copy medium description artist ID

列出数据库中记录有多个副本的任何艺术品(包括创作该作品的艺术家)的详细信息的 SQL 查询是什么?

4

1 回答 1

1

尝试这个:

SELECT 
  w.copy, w.title, w.description, w.medium, 
  a.firstname + ' ' + a.lastname AS 'Artist created the work'
FROM artists a
INNER JOIN
(
    SELECT * 
    FROM work 
    WHERE artistID IN
    ( 
        SELECT artistID
        FROM work 
        GROUP BY artistID
        HAVING COUNT(*) > 1 
    )
) w ON a.artistID = w.artistID

这是SQL Fiddle 中的演示

于 2012-09-23T09:26:25.687 回答