I have three tables T1, T2 and T3 with every table as bpm_no common in all the tables. Table T1 is the main table. T1 have every row with unique bpm_no (not repeating). Table T2 includes two column one is bpm_no and another is user, here one bpm_no can occur multiple times with different users working on same bpm_no. Table T3 includes two column one is bpm_no and another is total_outstanding, here also one bpm_no can occur multiple times with different total_outstanding, as one bpm_no can have different outstanding from different bank.
Now, I have to write the procedure which will construct a table using all the above tables (inner join) and it must include three column, one which will include bpm_no (unique for each row), another with users with comma separated for each individual bpm_no, and the last column with the sum of total_outstanding. Idea is to have the end table with every bpm_no as unique and its resulting values with comma separated and loan as sum.
I, tried using Views, but It will not work as in that case I will have to create lots of views. Kindly suggest other ways.
Below is the table structure for better understanding:
Table T1:
|---------------------|------------------|
| **bpm_no** | **name** |
|---------------------|------------------|
| abc_0011 | john |
|---------------------|------------------|
Table T2:
|---------------------|------------------|
| **bpm_no** | **user** |
|---------------------|------------------|
| abc_0011 | abc |
|---------------------|------------------|
| abc_0011 | bcd |
|---------------------|------------------|
| abc_0011 | lmn |
|---------------------|------------------|
Table T3:
|---------------------|------------------|
| **bpm_no** | **loan_os** |
|---------------------|------------------|
| abc_0011 | 14,500 |
|---------------------|------------------|
| abc_0011 | 4000 |
|---------------------|------------------|
| abc_0011 | 5000 |
|---------------------|------------------|
Final Table required:
|---------------------|------------------|------------------|
| **bpm_no** | **user** | **loan_os** |
|---------------------|------------------|------------------|
| abc_0011 | abc,bcd,lmn | 23,500 |
|---------------------|------------------|------------------|