2 ms·
Ditto, thanks for sharing the articles. For a trivially small set of mapping data, I like using VALUES to create a "virtual" staging table: UPDATE reward_
by ilikepi 9y ago
Ditto, thanks for sharing the articles.
For a trivially small set of mapping data, I like using VALUES to create a "virtual" staging table:
UPDATE reward_members
SET member_status = status_map.new_status
FROM (VALUES ('gold', 'gold_group'),
('bronze', 'bronze_group'),
('platinum', 'platinum_group'),
('silver', 'silver_group')
) AS status_map (old_status, new_status)
WHERE member_status = status_map.old_status;
I find this to be more readable than the CASE statement version.
- infogulch 9y agoI was looking through the thread for this solution. It's great because it's much harder to mess up and is less verbose than a case, and it's built on common SQL features making it portable and fast and easy to grok (as long as both the engine and the dba knows how joins work). As a data analyst this technique is also great for scrubbing dirty data at query time when you don't have the ability to just fix it.
- ilikepi 9y agoYeah, I use it in queries as well. Good point!