1

我有四张桌子:

  PAINTING            GALLERY             ARTIST              PAINTED
- PAINTING_TITLE    - GALLERY_ID        - ARTIST_ID         - PAINTED_CODE
- PAINTING_ID       - GALLERY_NAME      - ARTIST_LAST       - ARTIST_ID
                                        - ARTIST_FIRST      - PAINTING_ID

PAINTED 表记录了每位艺术家绘制的画作。有些画是由不止一位艺术家绘制的。我想返回两位艺术家绘制的画作列表。

SELECT
    PAINTING.PAINTING_TITLE AS TITLE, 
    GALLERY.GALLERY_NAME AS GALLERY
FROM
    PAINTING,
    GALLERY,
    PAINTED
WHERE
        PAINTING.GALLERY_ID = GALLERY.GALLERY_ID
    AND
        PAINTING.PAINTING_ID = PAINTED.PAINTING_ID
GROUP BY
    PAINTING.PAINTING_TITLE,
    GALLERY.GALLERY_NAME
HAVING
    COUNT(PAINTED.ARTIST_ID) = 2

这可行,但结果中不包含艺术家的姓名。我需要将每位艺术家的姓名与画廊名称和艺术品名称一起列出,每个名称将出现两次,但一次与不同的艺术家一起出现。

我正在使用 Access SQL。

4

1 回答 1

0

用这个:

SELECT
    PAINTING.PAINTING_TITLE AS TITLE, 
    GALLERY.GALLERY_NAME AS GALLERY,
    ARTIST.ARTIST_FIRST & " " & ARTIST.ARTIST_LAST
FROM
    PAINTING,
    GALLERY,
    PAINTED,
    ARTIST,
WHERE
        PAINTING.GALLERY_ID = GALLERY.GALLERY_ID
    AND
        PAINTING.PAINTING_ID = PAINTED.PAINTING_ID
    AND
        ARTIST.ARTIST_ID = PAINTED.ARTIST_ID
GROUP BY
    PAINTING.PAINTING_TITLE,
    GALLERY.GALLERY_NAME
HAVING
    COUNT(PAINTED.ARTIST_ID) = 2
于 2013-10-21T08:49:45.293 回答