Rename columns from a mapping table (ledger)
Finance keeps a two-column table of old and new column names. Apply it, ignoring names the export doesn't have.
- Level
- advanced
- Time
- ~9 min
- Task
- Build the query
- Access
- Free — no account needed
Loading the practice workspace…
About this exercise
What you'll practise
Drive renaming from data (a mapping table) and tolerate mappings that don't apply.
Brightline Advisory (fictional) receives ledger exports from several client systems and maps their column names to its own standard.
Steps
Mappinghas columnsOldandNew. Rename every column ofExportwhose name appears inOldto the matchingNew.- Some
Oldnames don't exist in this export; ignore them. Columns not in the mapping keep their names. - Don't type any column names into the query.
Your result must
- Mapped columns renamed
- Unmapped columns unchanged
- Mappings for missing columns don't cause errors
Input
- Export (table)
- cr: text
- desc: text
- dr: text
- acct: text
- ref: text
- Mapping (table)
- Old: text
- New: text
Expected output columns
cr (text), Description (text), Debit (text), Account (text), ref (text)
| cr | Description | Debit | Account | ref |
|---|---|---|---|---|
| cr-1 | desc-1 | dr-1 | acct-1 | ref-1 |
| cr-2 | desc-2 | dr-2 | acct-2 | ref-2 |
| cr-3 | desc-3 | dr-3 | acct-3 | ref-3 |