gpt4 book ai didi

MYSQL错误 'unknown column in having clause'

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

查询如下,我收到错误:

SELECT a.name
FROM author a, catalog c
WHERE a.authorid = c.authorid
AND c.bookid IN (
SELECT bookid
FROM orderdetails
GROUP BY bookid
HAVING sum(quantity) = (
SELECT max(sum(quantity))
FROM orderdetails
)
);

下表由图书经销商维护。

AUTHOR (author-id:int, name:string, city:string, country:string)
PUBLISHER (publisher-id:int, name:string, city:string, country:string)
CATALOG (book-id:int, title:string, author-id:int, publisher-id:int, category-id:int, year:int, price:int)
CATEGORY (category-id:int, description:string)
ORDER-DETAILS (order-no:int, book-id:int, quantity:int)

问题是:

四。查找销量最高的书的作者。

最佳答案

您可能需要一个中间组

  select a.name 
from author a
inner join catalog c on a.authorid=c.authorid
and c.bookid in (select bookid
from orderdetails
group by bookid
having sum(quantity) = (
select max( sum_quantity) from (
select sum(quantity) sum_quantity
from orderdetails
group by bookid
)
);

关于MYSQL错误 'unknown column in having clause',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40915097/

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