如何计算特定范围内的交易数量(How to calculate number of transactions within a specific range)

编程入门 行业动态 更新时间:2024-10-28 21:20:50
如何计算特定范围内的交易数量(How to calculate number of transactions within a specific range)

任何人都可以帮助解释如何使用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

Can anybody help on how to calculate number of transactions within this range for last year sales using TSQL. I don't have a clue on how to populate that range and link it with my sales total in the database

0.01- 5.00, 5.001 -10.00, 10.01 - 15.00

I have tried to use this code below,

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

最满意答案

有点

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;

根据真实的表格结构进行调整。

Kind of

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;

Adjust according to the real table structure.

更多推荐

本文发布于:2023-07-30 08:27:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1336772.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:范围内   数量   calculate   number   specific

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!