求一条sql查询语句?
我现在有一个表:
order_ID: 订单编号
BookID: 图书编号 这两个是主键
BookSellprice :图书单价
Bookamount: 图书数量
现在要取出相同图书既BookID相同的,图书数量总和最大的前10个BookID
这是我在做一本书上的例子,求销售排行,请各位帮忙想一想??
------解决方案--------------------select top 10 sum(Bookamount) as qty,BookID from yourtablename group by BookID order by qty desc
------解决方案--------------------求数量排行榜:
select top 10 sum(Bookamount) as BookTotal ,BookID from 表名 group by BookID order by BookTotal desc
求销售价格排行榜
select top 10 BookID,sum(BookSellprice*Bookamount) as BookTotal from 表名 group by BookID order by BookTotal desc