sql - Postgres Self Join query -
the db schema along sample data -
country table
| country | country code | -------------------------- abc ae bcd rw
dest table
| destcountry code | destcurrency code | totaldestamount | ---------------------------------------------------------- rw usd 3600 rw usd 13000 ae rwf 8880 ae usd 0
src table
| srccountry code | srccurrency code | totalsrcamount | --------------------------------------------------------- ae usd 7 rw rwf 10 ae aed 399 ae usd 0
i want output -
| mapping | srcamount| destamount | currency | ----------------------------------------------- abc-bcd 7 0 usd bcd-abc 10 13000 rwf abc-bcd 399 8880 aed bcd-abc 0 3600 usd
each country mapping should have individual incoming , outgoing currencies. ex - when talking abc-bcd, srcamount refers amount in abc src going bcd particular currency. destamount refers amount coming in abc bcd (again particular currency).
Comments
Post a Comment