gpt4 book ai didi

mysql - sql max 函数错误 : Incorrect syntax near the keyword 'select'

转载 作者:行者123 更新时间:2023-11-29 05:54:29 26 4
gpt4 key购买 nike

我有下一个 sql 代码,您可以在下面看到。除了带有 where 条件的最后一行,它都可以工作。

    select m.model,m.price from (
select product.model, pc.price
from product
join pc
on product.model=pc.model
union
select product.model, laptop.price
from product
join laptop
on product.model=laptop.model
union
select product.model, printer.price
from product
join printer
on product.model=printer.model
) m
where m.price = select max(m.price) from m

我有下一个错误:关键字“select”附近的语法不正确。如果我把最后一行写成:where m.price = m.price 它也可以工作

最佳答案

您是否按型号追求最高价格?

select m.model,MAX(m.price) as price from 
(
select product.model, pc.price
from product
join pc
on product.model=pc.model
union
select product.model, laptop.price
from product
join laptop
on product.model=laptop.model
union
select product.model, printer.price
from product
join printer
on product.model=printer.model
) m
GROUP BY m.model

关于mysql - sql max 函数错误 : Incorrect syntax near the keyword 'select' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50958896/

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