You are given two denormalized tables. Use ANSI SQL (CTEs allowed) and UNPIVOT (or an equivalent UNION ALL approach if UNPIVOT is unavailable).
Table: advertiser_spend Columns: advertiser_id INT, advertiser_name VARCHAR, spend_prog_A DECIMAL, spend_prog_B DECIMAL, spend_prog_C DECIMAL Sample data: +---------------+----------------+--------------+--------------+--------------+ | advertiser_id | advertiser_name| spend_prog_A | spend_prog_B | spend_prog_C | +---------------+----------------+--------------+--------------+--------------+ | 1 | AlphaCo | 1000 | 500 | NULL | | 2 | BetaInc | 200 | 1200 | 300 | | 3 | GammaLLC | 0 | 0 | 0 | | 4 | DeltaAds | 700 | 800 | 900 | +---------------+----------------+--------------+--------------+--------------+
Table: program_financials Columns: program_code CHAR(1), revenue DECIMAL, cost DECIMAL Sample data: +--------------+---------+------+ | program_code | revenue | cost | +--------------+---------+------+ | A | 5000 | 3500 | | B | 3000 | 2800 | | C | 2000 | 500 | +--------------+---------+------+
Mapping: spend_prog_A->'A', spend_prog_B->'B', spend_prog_C->'C'.
Task: