I hope you all are doing great! :D
I need your help to get the following done:
I need to create the following table:
| Date | Revenue gained from new deals | Revenue lost from churn | Revenue gained from upsell |
|---|---|---|---|
| 01/jan/2022 | $1000 | -$500 | $1000 |
| 02/jan/2022 | $2000 | -$200 | $2000 |
The situation here is that to gather and aggregate this data I need to fetch 3 different tables:
deals, churns and upsells
The deals table:
| Deal | Closing date | Revenue won |
|---|---|---|
| Deal #1 | 01/jan/2022 | $500 |
| Deal #2 | 01/jan/2022 | $500 |
| Deal #3 | 02/jan/2022 | $1500 |
| Deal #4 | 02/jan/2022 | $500 |
The churns table:
| Churn | Closing date | Revenue lost |
|---|---|---|
| Churn #1 | 01/jan/2022 | -$500 |
| Churn #2 | 02/jan/2022 | -$100 |
| Churn #3 | 02/jan/2022 | -$100 |
The upsells table:
| Upsell | Closing date | Revenue won |
|---|---|---|
| Upsell #1 | 01/jan/2022 | $2000 |
| Upsell #2 | 01/jan/2022 | -$1000 |
| Upsell #3 | 02/jan/2022 | $2000 |
The first question is: How can I create a SQL command to get this done?
Thanks in advance.