/* SCD - Slowly Changing Dimension - Type 3 - State dimension */ /* Region for "New Jersey" and "Alaska" changed - A prev column is used */ select * from state; select * from state where region != region_prev; /* Display total tax collected by state */ select state_name, sum(tax) from payment join state using (state_code) group by state_name with rollup; /* Display total tax collected by current region and state */ select region, state_name, sum(tax), max(region_prev) "prev region" from payment join state using (state_code) group by region, state_name with rollup; /* Display total tax collected by previous region and state */ select region_prev, state_name, sum(tax), max(region) "curr region" from payment join state using (state_code) group by region_prev, state_name with rollup;