gpt4 book ai didi

mysql - 在 sql 查询中使用表的问题

转载 作者:行者123 更新时间:2023-11-29 12:29:19 24 4
gpt4 key购买 nike

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

我发布了它们herethere

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 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

关于mysql - 在 sql 查询中使用表的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27825863/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com