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

2025-01-03 19:25:07
推荐回答(5个)
回答1:

按照一行记录代表销售一个数量单位商品的话,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

回答2:

select top 10 title,count(*) as 销量 from a表 group by title having month(sdate)='月份' order by 销量 desc

回答3:

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
看看哪个适合你

回答4:

加一个 销售量(sales_volume) 吧!

select top 10 sales_volume from a order by sales_volume desc

回答5:

select top 10 title from a where month(sdate)=月份 group by title