Attualmente sto lavorando con una tabella simile a questa:
Month | Transaction | amount
2021-07-01| Annual Membership Fee| 45
2021-08-01| Annual Membership Fee| 145
2021-09-01| Annual Membership Fee| 2940
2021-10-01| Annual Membership Fee| 1545
il amount
in tale tabella è la totale importo mensile (ex. Ho 100 clienti che hanno pagato 15 $per l'abbonamento annuale, quindi il mio totale importo mensile sarebbe $1500).
Tuttavia quello che vorrei fare (e non ho idea di come) è dividere l'importo da 12 e a diffondere nel futuro, per avere un reddito mensile al mese. Un esempio per 2021-09-01 vorrei ottenere i seguenti:
$2490/12 = $207.5 (dollars per month for the next 12 months)
in 2021-09-01 I would only get $207.5 for that specific month.
On 2021-10-01 I would get $1545/12 = $128.75 plus $207.5 from the previous month (total = $336.25 for 2021-10-01)
And the same operation would repeat onwards. The last period that I would collect my $207.5 from 2021-09-01 would be in 2022-08-01.
Mi chiedevo se qualcuno potesse darmi un'idea di come eseguire questo in una query SQL/CTE?