0
select a.author_id,a.name,a.city,a.country from author a,catalog c 
where c.author_id=a.author_id 
and c.book_id=(select book_id from order_details 
group by book_id 
having sum(quantity)=(select max(quantity) 
from (select sum(quantity) as quantity from order_details group by book_id)));

我想找到销量最高的书的作者,但它显示错误。这有什么问题?

4

2 回答 2

0

你应该试试这个,如果问题不能解决,请联系我

select a.author_id,a.name,a.city,a.country 
from author a,catalog c 
where c.author_id=a.author_id 
and c.book_id=(select book_id 
           from order_details d
           group by d.book_id 
           having sum(quantity)=(select max(e.quantity ) 
                                   from (select sum(dd.quantity) as quantity 
                                         from order_details dd 
                                         group by dd.book_id) as e ) );
于 2017-02-03T07:02:43.397 回答
0

在 from 子句之后使用别名

select a.author_id,a.name,a.city,a.country 
from author a,
     catalog c 
where c.author_id=a.author_id 
      and c.book_id=(select book_id 
                     from order_details 
                     group by book_id 
                     having sum(quantity)=(select max(quantity) 
                                           from (select sum(quantity) as 
                                                 quantity 
                                                 from order_details 
                                                 group by book_id)
                                                )a
                                          );
于 2017-02-03T05:51:12.437 回答