I am wanting to use Postgres transforming rows data into columns. I have id and value column, id column will have value as 'Account_Number' and 'Account_Holder_Name' and value column corresponding to the actual value.
The below table is the representation of the data I will hold in a table and belongs to the custom fields, so the id column may also contain more field names and the value field will contain the actual value of that field
Table: trans
id | type | booking_date |
---|---|---|
1 | Deposit | 2022-02-02 |
2 | Withdraw | 2022-02-03 |
Table: trans_custom_fields
id | value | transId |
---|---|---|
ACCOUNT_HOLDER_NAME | Manoj Sharma | 1 |
ACCOUNT_NUMBER | 113565TTE44656 | 1 |
RECIPT_NUMBER | 24324. | 1 |
ACCOUNT_HOLDER_NAME | Another User | 2 |
ACCOUNT_NUMBER | 35546656TRFG23 | 2 |
RECIPT_NUMBER | 24324686 | 2 |
Now I am want to transform this table data in the below format which can be used in the join query too and shown as a single record.
Table: join resultset
ACCOUNT_HOLDER_NAME | ACCOUNT_NUMBER | RECIPT_NUMBER | transId |
---|---|---|---|
Manoj Sharma | 113565TTE44656 | 24324 | 1 |
Another User | 35546656TRFG23 | 24324686 | 2 |
What can I try next?