题目:本题目要求编写SQL语句,查询具有最高价格的机器的型号,机器包括PC、Laptop、Printer。
提示:请使用SELECT语句作答。
表结构:
表样例:
输出样例
思路:将三个表做一个连接构造自己需要的新表,然后表中价格是所有设备价格的最大值即可。(新表不需要所有属性)
select model
from(
select price,model
from pc
union
select price,model
from laptop
union
select price,model
from printer
)as a
where price =(/*查询价格的最大值*/
select greatest(
(select max(price)from pc),
(select max(price)from laptop),
(select max(price)from printer)
)
);