Skip to content

Instantly share code, notes, and snippets.

@graham-thomson
Created April 1, 2016 14:16
Show Gist options
  • Save graham-thomson/2c0da4ece10271c19116201772c271f6 to your computer and use it in GitHub Desktop.
Save graham-thomson/2c0da4ece10271c19116201772c271f6 to your computer and use it in GitHub Desktop.
--Create a temp table with a sample of recent daily pivot date (Note: TEMP TABLEs only exist for the duration of your connection to the database.)--
CREATE TEMP TABLE sample_daily AS(SELECT * FROM adobe_data.dat_daily_pivot WHERE sample_start_date <= '2016-03-30' ORDER BY sample_start_date DESC LIMIT 100);
--Check initial total_sales sum--
SELECT SUM(total_sales) FROM sample_daily;
-->>1800.2825
--Update <table_name> SET <col_name> = <what you want to update the column to> WHERE <where clause>--
UPDATE sample_daily SET total_sales = total_sales * 4 WHERE sample_start_date <= '2016-03-30';
--Check update total sales--
SELECT SUM(total_sales) FROM sample_daily;
-->>7201.1300
--QA--
SELECT (1800.2825 * 4)::numeric;
-->>7201.1300
--Ready to do on production table--
UPDATE adobe_data.dat_daily_pivot SET total_sales = total_sales * 4 WHERE sample_start_date <= '2016-03-30';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment