此查询可以工作并生成以下数据:
select book_id, sum(quantity*order_price) as TExtCost
from bkorders.order_details
group by book_id
order by sum(quantity*order_price) desc
book_id TExtCost
1128 31909.34
1401 29966.00
1108 28410.30
.
.
.
下一步是找到这些行的顶部(1)。我知道我不能使用嵌套聚合,但我想这样做:
选择book_id,top(1)sum(quantity * order_price))作为TopSeller
建议?
答案 0 :(得分:0)
select top 1 * from (
select book_id, sum(quantity*order_price) as TExtCost
from bkorders.order_details
group by book_id
) a order by TExtCost desc