I have data with date, userid, and amount. I want to calculate sum(amount) divided by total day for each month. the final will be presented in monthly basis.
The table I have is looks like this
date userid amount
2019-01-01 111 10
2019-01-15 112 20
2019-01-20 113 10
2019-02-01 114 30
2019-02-15 111 20
2019-03-01 115 40
2019-03-23 155 50
desired result is like this
date avg_qty_sol
Jan-19 1.29
Feb-19 1.79
Mar-19 2.90
avg_qty_sold is coming from sum(amount) / total day for respective month e.g for jan 2019 sum amount is 40 and total days in jan is 31. so the avg_qty_sold is 40/31
Currently Im using case when for this solution. is there any better approach to this?