SQL:按事务数除以int

时间:2017-05-25 20:24:46

标签: sql sql-server

我需要将TWin除以一段时间内的交易数量。 例如:如果客户的TWin为100,则在1月1日至5月之间的5天内出现5月1日= 20。 请帮忙。谢谢。

select PlayerID, CashIn, **TWin/SUM(GamingDate)** as Daily_Theo, PtsEarned
from CDS_StatDay
where GamingDate between '1/1/2017' and '5/1/2017'
group by PlayerID, CashIn, TWin, PtsEarned
order by CDS_StatDay.PlayerID asc

1 个答案:

答案 0 :(得分:0)

如果我理解你想要做什么,请尝试这样的事情

select v.PlayerID, v.CashIn, v.TWin, v.PtsEarned,
       case cnt when 0 then 0 else v.TWin / v.cnt end as Daily_Theo
from (
select PlayerID, CashIn, TWin, count(GamingDate) over (partition by PlayerID) as cnt,
   PtsEarned
from CDS_StatDay
where GamingDate between '1/1/2017' and '5/1/2017'
) v
order by v.PLayerID