任何人都可以帮助我们使用TSQL计算去年销售额在此范围内的交易数量。我不知道如何填充该范围并将其与我在数据库中的销售总额相关联
0.01- 5.00,
5.001 -10.00,
10.01 - 15.00
我试过使用下面的代码,
SELECT COUNT (*) as Nooftransactions, Floor (Amount)/5 As Range, Convert(Varchar(max), (5*Floor(Linetotal/5))) +'0.01' + '-' + Convert(Varchar(max), (5*floor(Linetotal/5) +5))) + '0.00' as Rangesplit
Group by Amount,Floor (Amount)/5 , Convert(Varchar(max), (5*Floor(Linetotal/5))) +'0.01' + '-' + Convert(Varchar(max), (5*floor(Linetotal/5) +5))) + '0.00'
Order Amount
答案 0 :(得分:0)
有点
select ranges.lo, ranges.hi,
count(*) as [number of transactions]
from transactions t
join (
values (0.01, 5.00), (5.001, 10.00), (10.01, 15.00)
) ranges(lo, hi)
on t.value between ranges.lo and ranges.hi
group by ranges.lo, ranges.hi
order by ranges.lo;
根据实际表格结构进行调整。