日期:2014-05-17 浏览次数:20572 次
--按订单数 select User.UserID, min(User.UserName) 姓名, count([Order].OrderID) 订单数量 from [User] left join [Order] on User.UserID=[Order].UserID group by User.UserID order by 订单数量 desc; --按销售数 select User.UserID, min(User.UserName) 姓名, sum(OrderUnit*OrderNum) 销售数量 from [User] left join [Order] on User.UserID=[Order].UserID group by User.UserID order by 销售数量 desc;
------解决方案--------------------
--各个产品的销量情况 select b.[UserName],a.[OrderName],sum(a.[OrderUnit]*a.[OrderNum]) 销量 from [Order] a,[User] b where a.[UserID]=b.[UserID] group by b.[UserName],a.[OrderName] order by a.[OrderName],sum(a.[OrderUnit]*a.[OrderNum]) desc --总的销量情况 select b.[UserName],sum(a.[OrderUnit]*a.[OrderNum]) 销量 from [Order] a,[User] b where a.[UserID]=b.[UserID] group by b.[UserName] order by sum(a.[OrderUnit]*a.[OrderNum]) desc
------解决方案--------------------