Basically I have a database and I need to extract data on a per month and per company type basis. I'm using psql.
Alternatively, it can also look like this
Basically I want the cumulative sum of each type compunded on each other. Is that at all possible?
inputs:
table1 has client, start date, sum
table2 has client, company type
so far, I have this
SELECT DISTINCT(date_trunc('month',start_date)) AS month, company_type, SUM(current_interest) OVER(PARTITION BY company_type ORDER BY start_date) AS cumulative_sum FROM table1 INNER JOIN table2 ON table1.client_id = table2.client_id GROUP BY month, company_type, start_date, current_interest ORDER BY month, company_type DESC;
Right now what I'm getting is something like this. Is there anyway to combine all same company type to show just the total for the whole month instead of per input.
What I want is something like this. Sorry if the title is misleading, not really sure what to call it. Any help is appreciated, Thanks!