I have a table 'pay_schedule' which looks like this:
------------------------------------------------------------------------------ Title (char[50]) | FilmId (int) payout (Dec(18,2)) pay_date (date) | ------------------------------------------------------------------------------| Big Secret | -2147483648 | 900.00 | 4/9/2017 | puzzled | -2147483631 | 512.50 | 4/9/2017 | puzzled | -2147483631 | 325.94 | 4/9/2017 | puzzled | -2147483631 | 325.94 | 7/9/2017 | Star men | -2147483639 | 512.5 | 7/9/2017 | Deep beneath | -2147483636 | 900 | 7/9/2017 | Deep beneath | -2147483636 | 900 | 10/9/2017 | Deep beneath | -2147483636 | 512.5 | 10/9/2017 | Deep beneath | -2147483636 | 325.94 | 10/9/2017 | puzzled | -2147483631 | 325.94 | 1/9/2018 | Star ment | -2147483639 | 512.5 | 1/9/2018 | puzzled | -2147483639 | 900 | 1/9/2018 | Mirzya | -2147483639 | 900 | 4/9/2018 | puzzled | -2147483639 | 512.5 | 4/9/2018 | ..... | .......... | ...... | ..... | | | | |
I would like to get a result of :
- SUM(payout) for each of the title for each month
- Total payout for month per month between a start date and end date. Like illustrated under:
Start Date: 01/01/2017 End Date: 12/31/2019 ------------------------------------------------------------------------- Month Y | Big Secret |Deep beneath | puzzled | star men | | | | | | ------------------------------------------------------------------------| apr 2017 | 900.00 | 0.00 | 838.44 | 0.00 | jul 2017 | 0.00 | 900.00 | 325.94 | 512.50 | oct 2017 | 0.00 | 1738.44 | 0.00 | 0.00 | jan 2018 | 0.00 | 0.00 | 1225.94 | 512.50 | apr 2018 | 900.00 | | 512.50 | | _________________________________________________________________________
** Months not included where payout is not there
I appreciate your time and help very much. Since this is a large table I would appreciate if you point to possible optimizations too. Have a good day!