在 sql 查询中使用表的问题

Issue with using tables in sql queries

以下两个查询存在语法问题,我不知道如何解决

我发布了它们 here and there

select model from  
(
select model, price from PC
join Product
on Product.model=PC.model
union all 
select model, price from Laptop
join Product
on Product.model=Laptop.model
union all 
select model, price from Printer
join Product
on Product.model=Printer.model
) XXX
where price = (select max(price) from XXX);

select model from 
(
  select model, price from pc  
  union all
  select model, price from laptop
  union all
  select model price from printer 
) as x
where price=greatest( select max(price) from pc,
                      select max(price) from laptop,
                      select max(price) from printer )

您要确定价格最高的型号吗?如果是这样,只需将您的查询更改为按价格和 select 个结果排序。

select model from  
(
select model, price from PC
join Product
on Product.model=PC.model
union all 
select model, price from Laptop
join Product
on Product.model=Laptop.model
union all 
select model, price from Printer
join Product
on Product.model=Printer.model
) XXX
order by price desc limit 0, 1;

您可以对第二个查询使用相同的技术,如下所示:

select model from 
(
  select model, price from pc order by price desc limit 0, 1 
  union all
  select model, price from laptop order by price desc limit 0, 1
  union all
  select model, price from printer order by price desc limit 0, 1
) as x