分数 10
全屏浏览题目
切换布局
作者 lhm
单位 河北农业大学
本题目要求编写SQL语句,查询具有最高价格的机器的型号,机器包括PC、Laptop、Printer。
提示:请使用SELECT语句作答。
表结构:
CREATE TABLE pc
( model CHAR(20) NOT NULL, --型号
speed DECIMAL(6,2), --速度
ram INT, --内存
hd DECIMAL(6,2), --硬盘容量
cd CHAR(4), --光驱
price INT, --价钱
PRIMARY KEY(model)
);
CREATE TABLE laptop
( model CHAR(20) NOT NULL, --型号
speed DECIMAL(6,2), --速度
ram INT, --内存
hd DECIMAL(6,2), --硬盘容量
screen DECIMAL(6,2), --屏幕大小
price INT, --价钱
PRIMARY KEY(model)
);
CREATE TABLE printer
( model CHAR(20) NOT NULL, --型号
color BIT, --是否彩色
type CHAR(10), --类型
price INT, --价钱
PRIMARY KEY(model)
);
表样例
pc
表:
model | speed | ram | hd | cd | price |
---|---|---|---|---|---|
1001 | 133.00 | 16 | 1.60 | 6X | 1595 |
1002 | 120.00 | 16 | 1.60 | 6X | 1399 |
1003 | 166.00 | 24 | 2.50 | 6X | 1899 |
1004 | 166.00 | 32 | 2.50 | 8X | 1999 |
1008 | 180.00 | 32 | 2.00 | 8X | 3699 |
1009 | 200.00 | 32 | 2.50 | 8X | 2599 |
laptop
表:
model | speed | ram | hd | screen | price |
---|---|---|---|---|---|
2001 | 100.00 | 20 | 1.10 | 9.50 | 1999 |
2002 | 117.00 | 12 | 0.75 | 11.30 | 2499 |
2003 | 117.00 | 32 | 1.00 | 11.20 | 3599 |
printer
表:
model | color | type | price |
---|---|---|---|
3001 | 1 | 喷墨 | 275 |
3002 | 1 | 喷墨 | 269 |
3003 | 0 | 激光 | 829 |
3004 | 0 | 激光 | 879 |
输出样例:
model |
---|
1008 |
select a.model from
(select pc.model,pc.price from
pc
union
select laptop.model,laptop.price from
laptop
union
select printer.model,printer.price from
printer) a
where a.price = (select max(price) from
(select pc.model,pc.price from
pc
union
select laptop.model,laptop.price from
laptop
union
select printer.model,printer.price from
printer) a
)