raw_data :
| name | account_id | type | element_id | cost |
|---|---|---|---|---|
| First | 1 | type1 | element1 | 0.1 |
| Second | 2 | type2 | element2 | 0.2 |
| First | 11 | type2 | element11 | 0.11 |
components:
| name | account_id (default = -1) | type (default = null) | element_id (default = null) | cost |
|---|---|---|---|---|
| First | -1 | null | null | 0.1 |
| Second | 2 | type2 | null | 0.2 |
| First | 11 | type2 | element11 | 0.11 |
I seek to check whether the cost logged in raw_data is the same as that in components for a given combination. They need to be joined on column name.
Remaining fields in raw_data are always populated. In components, any row can be a combination of specific values and the default values.
I seek to match the columns from raw_data to components wherever I find a match and otherwise need to use the default value to get the cost.
I failed with left join and union and IN.
E.g. For the first row in raw_data table with name "First", I do not have account_id = 1 in the components table. So I need to go with account_id = -1.
Match as many specific values as found in components, Otherwise resort to default values.