第六章多于两个表的连接

customer 客户表   ord 订单表  item 产品表
CREATE TABLE customer(
id         int not NULL PRIMARY KEY,
cust_name  VARCHAR(20) not NULL
);

CREATE TABLE cust_order(
id         int not NULL PRIMARY KEY,
cust_id    int not NULL,
buy_time   date 
);

CREATE TABLE item(
id         int not NULL PRIMARY KEY,
ord_id     int not NULL,
item_name  VARCHAR(100) not NULL
);
查询谁买了多少商品
SELECT item_name 商品名称 FROM item,customer,cust_order
WHERE item.ord_id=cust_order.id
AND customer.id=cust_order.cust_id
AND cust_name='李特';```

你可能感兴趣的:(第六章多于两个表的连接)