0

我必须使用以下条件编写查询:

编写查询以仅列出已订购商品的标题和艺术家。每个标题只列出一次。

以下是创建的无法更改的 CREATE 表。

CREATE TABLE artists
(
    artist_id   INT NOT NULL,
    artist_name VARCHAR(30),

    CONSTRAINT artist_pk PRIMARY KEY (artist_id)
);

CREATE TABLE items
(  
    item_id    INT NOT NULL,  
    title      VARCHAR(50) NOT NULL,
    artist_id  INT NOT NULL,
    unit_price DECIMAL(9,2) NOT NULL,  

    CONSTRAINT items_pk PRIMARY KEY (item_id),
    CONSTRAINT items_fk_artists
        FOREIGN KEY (artist_id) REFERENCES artists (artist_id)
);

CREATE TABLE orders
(  
    order_id     INT NOT NULL,
    customer_id  INT NOT NULL,
    order_date   DATE NOT NULL,  
    shipped_date DATE, 
    employee_id  INT,  

    CONSTRAINT orders_pk PRIMARY KEY (order_id),
    CONSTRAINT orders_fk_customers
        FOREIGN KEY (customer_id) REFERENCES customers (customer_id),
    CONSTRAINT orders_fk_employees
        FOREIGN KEY (employee_id) REFERENCES employees (employee_id)
);

这是我为我的脚本所做的。

SELECT 
    items.title, artists.artist_name, orders.order_date
FROM 
    items
JOIN 
    orders
JOIN 
    artists;

请让我知道如何巩固。

4

1 回答 1

0

您应该根据表之间的键来说明表的结构。

于 2018-06-02T16:43:19.877 回答