Hi all,
I am trying to aggregate the transaction data monthly within a year of 2017 from the customer location table then convert from row to column.
Please do not use Pivot function as I am not using MSSQL but using database without Pivot function but it does accept SQL.
Here is the input tables:
I would like to aggregate the data become the output like below:
Appreciate you guys help on this.
I am trying to aggregate the transaction data monthly within a year of 2017 from the customer location table then convert from row to column.
Please do not use Pivot function as I am not using MSSQL but using database without Pivot function but it does accept SQL.
Here is the input tables:
Code:
Customer_table
Cust_ID Name Address effective_date expiry_date
1 John Smith New York 2016-02-01 2017-03-10
1 John Smith London 2017-03-11 9999-12-31
2 Jacky Fung Sydney 2017-01-01 9999-12-31
Transaction_Table
Cust_ID Tran_Date Tran_Amount
1 2017-03-05 100
1 2017-03-07 150
1 2017-03-15 200
1 2017-04-01 300
1 2017-05-10 400
1 2017-05-12 500
2 2017-03-05 100
2 2017-03-15 200
2 2017-04-01 300
2 2017-05-10 400
2 2017-05-12 500
I would like to aggregate the data become the output like below:
Code:
Cust_Id Effective_date Expiry_date Adress Mth01_Tot Mth02_Tot Mth03_Tot Mth04_Tot Mth05_Tot Mth06_Tot Mth07_Tot Mth08_Tot Mth09_Tot Mth10_Tot Mth11_Tot Mth12_Tot
1 2017-01-01 2017-03-10 New York null null 250 null null null null null null null null null
1 2017-03-11 9999-12-31 London null null 200 300 900 null null null null null null null
2 2017-01-01 9999-12-31 Sydney null null 300 300 900 null null null null null null null
Appreciate you guys help on this.