每个派生表必须有自己的别名 - 无法找到错误

时间:2017-02-03 05:48:26

标签: mysql mysql-error-1248

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

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

2 个答案:

答案 0 :(得分: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)
                                                )a
                                          );

答案 1 :(得分: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 ) );