嗨,我有这个数据库结构db structure,我需要选择从最昂贵的到最便宜的订购的所有设备。输出应该有序列号,制造商,价格,类型,但制造商属性是在产品表,我不知道如何添加到查询。属性与所有表共同是型号。
table Laptop (serial_number varchar(50),
model,
price,
speed,
ram,
hd,
screen,
CONSTRAINT laptop_pk PRIMARY KEY (serial_number),
CONSTRAINT laptop_2_product_fk
FOREIGN KEY (model)
REFERENCES Product(model));
table Product (model varchar(50),
maker,
type,
CONSTRAINT product_pk PRIMARY KEY (model));
table Printer (serial_number varchar(50),
model,
price,
color,
type,
CONSTRAINT printer_pk PRIMARY KEY (serial_number),
CONSTRAINT printer_2_product_fk
FOREIGN KEY (model)
REFERENCES Product(model));
table PC (serial_number varchar(50),
model,
price,
speed,
ram,
hd,
cd,
CONSTRAINT pc_pk PRIMARY KEY (serial_number),
CONSTRAINT pc_2_product_fk
FOREIGN KEY (model)
REFERENCES Product(model));
table Storage (storage_id varchar(50),
model,
serial_number,
transfered_to);
我尝试这个,但当然这只是给予我的模型,我需要序列号,制造商,价格和类型。我尝试在livesql上。
WITH MAX
AS (
SELECT model, price FROM PC
UNION
SELECT model, price FROM Laptop
UNION
SELECT model, price FROM printer
)
SELECT model FROM MAX
WHERE price = (
SELECT MAX(price)
FROM MAX
)
1条答案
按热度按时间ar7v8xwq1#
必须连接所有表并选择所需列