求sql语句,统计某月销售量前10

a表,字段: id, title,price,sdate
id:自动
title:商品名称
price:价格
sdate:日期

统计某月商品销量最大的商品前10个.

按照一行记录代表销售一个数量单位商品的话,T_SQL语句如下:

DECLARE @beginDate datetime, @endDate datetime
SELECT @beginDate = '开始日期', @endDate = '结束日期'

SELECT TOP 10 title, COUNT(1) AS sellNumber
FROM TableA
WHERE sDate BETWEEN @beginDate AND @endDate
GROUP BY title
温馨提示:内容为网友见解,仅供参考
第1个回答  2009-12-29
select top 10 title,count(*) as 销量 from a表 group by title having month(sdate)='月份' order by 销量 desc
第2个回答  2009-12-29
select top 10 a表.id ,tt.* from a表,(select title as vv,count(*) as sort from a表 group by title order by sort desc) as tt where month(sdate)='月份' and a表.title=tt.vv order by sort desc

或是
select top 10 id,count(title) as x,price,sdate from a表 month(sdate)='月份' group by id,price,sdate order by count(title) desc
看看哪个适合你
第3个回答  2009-12-29
加一个 销售量(sales_volume) 吧!

select top 10 sales_volume from a order by sales_volume desc
第4个回答  2009-12-29
select top 10 title from a where month(sdate)=月份 group by title
相似回答