Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
CREATE TABLE "qt_8ed826ab67df664accc6de2588cdebe8" AS (
SELECT "f_s_stats_aaao0ttz87aj6u3"."campaign_id" AS "a_12529",
SUM( "f_s_stats_aaao0ttz87aj6u3"."f_impressions" ) AS "c_c23d0c3ff14cd87e",
TRUE AS "def_c23d0c3ff14cd87e"
FROM "f_s_stats_aaao0ttz87aj6u3"
WHERE ( 42264 = "f_s_stats_aaao0ttz87aj6u3"."dt_b_workrecorded_id" )
GROUP BY 1 )
ANALYZE "qt_8ed826ab67df664accc6de2588cdebe8"
CREATE TABLE "qt_2086e7088f09d6ce0e2b59e06a739683" AS (
SELECT "f_aw_stats_aaehbh2uk3adif6"."campaign_id" AS "a_12529",
SUM( "f_aw_stats_aaehbh2uk3adif6"."f_impressions" ) AS "c_b9ce20c4d0e01093",
TRUE AS "def_b9ce20c4d0e01093"
FROM "f_aw_stats_aaehbh2uk3adif6"
WHERE ( 42264 = "f_aw_stats_aaehbh2uk3adif6"."dt_b_workrecorded_id" )
GROUP BY 1 )
ANALYZE "qt_2086e7088f09d6ce0e2b59e06a739683"
CREATE TABLE "qt_9f075709d6d11e31a4781fb9ac741f4f" AS (
SELECT "f_yt_stats_aab4zny6pjamc7h"."campaign_id" AS "a_12529",
SUM( "f_yt_stats_aab4zny6pjamc7h"."f_impressions" ) AS "c_6dcd11732b172caa",
TRUE AS "def_6dcd11732b172caa"
FROM "f_yt_stats_aab4zny6pjamc7h"
WHERE ( 42264 = "f_yt_stats_aab4zny6pjamc7h"."dt_b_workrecorded_id" )
GROUP BY 1 )
ANALYZE "qt_9f075709d6d11e31a4781fb9ac741f4f"
CREATE TABLE "qt_7560edd32aa829ea57440233df2c9f0e" AS (
SELECT "f_campaign_aac91czox0avdri"."client_id" AS "a_12533",
"f_campaign_aac91czox0avdri"."subcampaign_id" AS "a_12537",
"f_campaign_aac91czox0avdri"."system_id" AS "a_12539",
"f_campaign_aac91czox0avdri"."begindate_id" AS "a_81994",
"f_campaign_aac91czox0avdri"."enddate_id" AS "a_81997",
SUM( (
CASE
WHEN ( 0 = (
CASE
WHEN ( COALESCE( "qt"."def_c23d0c3ff14cd87e",
FALSE ) OR COALESCE( "qt_1"."def_6dcd11732b172caa",
FALSE ) OR COALESCE( "qt_2"."def_b9ce20c4d0e01093",
FALSE ) )
THEN ( (
CASE
WHEN COALESCE( "qt_2"."def_b9ce20c4d0e01093",
FALSE )
THEN COALESCE( "qt_2"."c_b9ce20c4d0e01093",
0 )
ELSE 0
END ) + (
CASE
WHEN COALESCE( "qt_1"."def_6dcd11732b172caa",
FALSE )
THEN COALESCE( "qt_1"."c_6dcd11732b172caa",
0 )
ELSE 0
END ) + (
CASE
WHEN COALESCE( "qt"."def_c23d0c3ff14cd87e",
FALSE )
THEN COALESCE( "qt"."c_c23d0c3ff14cd87e",
0 )
ELSE 0
END ) )
ELSE 0
END ) )
THEN "f_yt_stats_aab4zny6pjamc7h"."f_impressions"
ELSE CAST( NULL AS INT )
END ) ) AS "c_4c0b2b88e2f8f6df",
( MAX( (
CASE
WHEN ( 0 = (
CASE
WHEN ( COALESCE( "qt"."def_c23d0c3ff14cd87e",
FALSE ) OR COALESCE( "qt_1"."def_6dcd11732b172caa",
FALSE ) OR COALESCE( "qt_2"."def_b9ce20c4d0e01093",
FALSE ) )
THEN ( (
CASE
WHEN COALESCE( "qt_2"."def_b9ce20c4d0e01093",
FALSE )
THEN COALESCE( "qt_2"."c_b9ce20c4d0e01093",
0 )
ELSE 0
END ) + (
CASE
WHEN COALESCE( "qt_1"."def_6dcd11732b172caa",
FALSE )
THEN COALESCE( "qt_1"."c_6dcd11732b172caa",
0 )
ELSE 0
END ) + (
CASE
WHEN COALESCE( "qt"."def_c23d0c3ff14cd87e",
FALSE )
THEN COALESCE( "qt"."c_c23d0c3ff14cd87e",
0 )
ELSE 0
END ) )
ELSE 0
END ) )
THEN 0
END ) ) IS NOT NULL ) AS "def_4c0b2b88e2f8f6df"
FROM ( ( ( ( "f_yt_stats_aab4zny6pjamc7h"
INNER JOIN "f_campaign_aac91czox0avdri" ON ( "f_yt_stats_aab4zny6pjamc7h"."campaign_id" = "f_campaign_aac91czox0avdri"."id" ) ) LEFT OUTER
JOIN "qt_8ed826ab67df664accc6de2588cdebe8" AS "qt" ON ( "f_yt_stats_aab4zny6pjamc7h"."campaign_id" = "qt"."a_12529" ) ) LEFT OUTER
JOIN "qt_9f075709d6d11e31a4781fb9ac741f4f" AS "qt_1" ON ( "f_yt_stats_aab4zny6pjamc7h"."campaign_id" = "qt_1"."a_12529" ) ) LEFT OUTER
JOIN "qt_2086e7088f09d6ce0e2b59e06a739683" AS "qt_2" ON ( "f_yt_stats_aab4zny6pjamc7h"."campaign_id" = "qt_2"."a_12529" ) )
WHERE ( ( "f_campaign_aac91czox0avdri"."agency_id" IN ( 103127 ) )
AND ( "f_campaign_aac91czox0avdri"."status_id" IN ( 1497088 ) )
AND ( 0 = (
CASE
WHEN ( ( "f_campaign_aac91czox0avdri"."agency_id" IN ( 103127 ) )
AND ( "f_campaign_aac91czox0avdri"."status_id" IN ( 1497088 ) )
AND ( COALESCE( "qt"."def_c23d0c3ff14cd87e",
FALSE ) OR COALESCE( "qt_1"."def_6dcd11732b172caa",
FALSE ) OR COALESCE( "qt_2"."def_b9ce20c4d0e01093",
FALSE ) ) )
THEN ( (
CASE
WHEN COALESCE( "qt_2"."def_b9ce20c4d0e01093",
FALSE )
THEN COALESCE( "qt_2"."c_b9ce20c4d0e01093",
0 )
ELSE 0
END ) + (
CASE
WHEN COALESCE( "qt_1"."def_6dcd11732b172caa",
FALSE )
THEN COALESCE( "qt_1"."c_6dcd11732b172caa",
0 )
ELSE 0
END ) + (
CASE
WHEN COALESCE( "qt"."def_c23d0c3ff14cd87e",
FALSE )
THEN COALESCE( "qt"."c_c23d0c3ff14cd87e",
0 )
ELSE 0
END ) )
ELSE 0
END ) )
AND ( 42264 = "f_yt_stats_aab4zny6pjamc7h"."dt_b_workrecorded_id" ) )
GROUP BY 1,
2,
3,
4,
5 )
ANALYZE "qt_7560edd32aa829ea57440233df2c9f0e"
CREATE TABLE "qt_f792eab9de23c56d439335bdf8ecbcb1" AS (
SELECT "f_campaign_aac91czox0avdri"."client_id" AS "a_12533",
"f_campaign_aac91czox0avdri"."subcampaign_id" AS "a_12537",
"f_campaign_aac91czox0avdri"."system_id" AS "a_12539",
"f_campaign_aac91czox0avdri"."begindate_id" AS "a_81994",
"f_campaign_aac91czox0avdri"."enddate_id" AS "a_81997",
SUM( (
CASE
WHEN ( 0 = (
CASE
WHEN ( COALESCE( "qt"."def_c23d0c3ff14cd87e",
FALSE ) OR COALESCE( "qt_1"."def_6dcd11732b172caa",
FALSE ) OR COALESCE( "qt_2"."def_b9ce20c4d0e01093",
FALSE ) )
THEN ( (
CASE
WHEN COALESCE( "qt_2"."def_b9ce20c4d0e01093",
FALSE )
THEN COALESCE( "qt_2"."c_b9ce20c4d0e01093",
0 )
ELSE 0
END ) + (
CASE
WHEN COALESCE( "qt"."def_c23d0c3ff14cd87e",
FALSE )
THEN COALESCE( "qt"."c_c23d0c3ff14cd87e",
0 )
ELSE 0
END ) + (
CASE
WHEN COALESCE( "qt_1"."def_6dcd11732b172caa",
FALSE )
THEN COALESCE( "qt_1"."c_6dcd11732b172caa",
0 )
ELSE 0
END ) )
ELSE 0
END ) )
THEN "f_s_stats_aaao0ttz87aj6u3"."f_impressions"
ELSE CAST( NULL AS INT )
END ) ) AS "c_8d6c86be281e79ef",
( MAX( (
CASE
WHEN ( 0 = (
CASE
WHEN ( COALESCE( "qt"."def_c23d0c3ff14cd87e",
FALSE ) OR COALESCE( "qt_1"."def_6dcd11732b172caa",
FALSE ) OR COALESCE( "qt_2"."def_b9ce20c4d0e01093",
FALSE ) )
THEN ( (
CASE
WHEN COALESCE( "qt_2"."def_b9ce20c4d0e01093",
FALSE )
THEN COALESCE( "qt_2"."c_b9ce20c4d0e01093",
0 )
ELSE 0
END ) + (
CASE
WHEN COALESCE( "qt"."def_c23d0c3ff14cd87e",
FALSE )
THEN COALESCE( "qt"."c_c23d0c3ff14cd87e",
0 )
ELSE 0
END ) + (
CASE
WHEN COALESCE( "qt_1"."def_6dcd11732b172caa",
FALSE )
THEN COALESCE( "qt_1"."c_6dcd11732b172caa",
0 )
ELSE 0
END ) )
ELSE 0
END ) )
THEN 0
END ) ) IS NOT NULL ) AS "def_8d6c86be281e79ef"
FROM ( ( ( ( "f_s_stats_aaao0ttz87aj6u3"
INNER JOIN "f_campaign_aac91czox0avdri" ON ( "f_s_stats_aaao0ttz87aj6u3"."campaign_id" = "f_campaign_aac91czox0avdri"."id" ) ) LEFT OUTER
JOIN "qt_8ed826ab67df664accc6de2588cdebe8" AS "qt" ON ( "f_s_stats_aaao0ttz87aj6u3"."campaign_id" = "qt"."a_12529" ) ) LEFT OUTER
JOIN "qt_9f075709d6d11e31a4781fb9ac741f4f" AS "qt_1" ON ( "f_s_stats_aaao0ttz87aj6u3"."campaign_id" = "qt_1"."a_12529" ) ) LEFT OUTER
JOIN "qt_2086e7088f09d6ce0e2b59e06a739683" AS "qt_2" ON ( "f_s_stats_aaao0ttz87aj6u3"."campaign_id" = "qt_2"."a_12529" ) )
WHERE ( ( "f_campaign_aac91czox0avdri"."agency_id" IN ( 103127 ) )
AND ( "f_campaign_aac91czox0avdri"."status_id" IN ( 1497088 ) )
AND ( 0 = (
CASE
WHEN ( ( "f_campaign_aac91czox0avdri"."agency_id" IN ( 103127 ) )
AND ( "f_campaign_aac91czox0avdri"."status_id" IN ( 1497088 ) )
AND ( COALESCE( "qt"."def_c23d0c3ff14cd87e",
FALSE ) OR COALESCE( "qt_1"."def_6dcd11732b172caa",
FALSE ) OR COALESCE( "qt_2"."def_b9ce20c4d0e01093",
FALSE ) ) )
THEN ( (
CASE
WHEN COALESCE( "qt_2"."def_b9ce20c4d0e01093",
FALSE )
THEN COALESCE( "qt_2"."c_b9ce20c4d0e01093",
0 )
ELSE 0
END ) + (
CASE
WHEN COALESCE( "qt"."def_c23d0c3ff14cd87e",
FALSE )
THEN COALESCE( "qt"."c_c23d0c3ff14cd87e",
0 )
ELSE 0
END ) + (
CASE
WHEN COALESCE( "qt_1"."def_6dcd11732b172caa",
FALSE )
THEN COALESCE( "qt_1"."c_6dcd11732b172caa",
0 )
ELSE 0
END ) )
ELSE 0
END ) )
AND ( 42264 = "f_s_stats_aaao0ttz87aj6u3"."dt_b_workrecorded_id" ) )
GROUP BY 1,
2,
3,
4,
5 )
ANALYZE "qt_f792eab9de23c56d439335bdf8ecbcb1"
CREATE TABLE "qt_22d49b093abb2e140390ccf0721e45ef" AS (
SELECT "f_campaign_aac91czox0avdri"."client_id" AS "a_12533",
"f_campaign_aac91czox0avdri"."subcampaign_id" AS "a_12537",
"f_campaign_aac91czox0avdri"."system_id" AS "a_12539",
"f_campaign_aac91czox0avdri"."begindate_id" AS "a_81994",
"f_campaign_aac91czox0avdri"."enddate_id" AS "a_81997",
SUM( (
CASE
WHEN ( 0 = (
CASE
WHEN ( COALESCE( "qt"."def_6dcd11732b172caa",
FALSE ) OR COALESCE( "qt_1"."def_b9ce20c4d0e01093",
FALSE ) OR COALESCE( "qt_2"."def_c23d0c3ff14cd87e",
FALSE ) )
THEN ( (
CASE
WHEN COALESCE( "qt_2"."def_c23d0c3ff14cd87e",
FALSE )
THEN COALESCE( "qt_2"."c_c23d0c3ff14cd87e",
0 )
ELSE 0
END ) + (
CASE
WHEN COALESCE( "qt"."def_6dcd11732b172caa",
FALSE )
THEN COALESCE( "qt"."c_6dcd11732b172caa",
0 )
ELSE 0
END ) + (
CASE
WHEN COALESCE( "qt_1"."def_b9ce20c4d0e01093",
FALSE )
THEN COALESCE( "qt_1"."c_b9ce20c4d0e01093",
0 )
ELSE 0
END ) )
ELSE 0
END ) )
THEN "f_aw_stats_aaehbh2uk3adif6"."f_impressions"
ELSE CAST( NULL AS INT )
END ) ) AS "c_494017f656057f9d",
( MAX( (
CASE
WHEN ( 0 = (
CASE
WHEN ( COALESCE( "qt"."def_6dcd11732b172caa",
FALSE ) OR COALESCE( "qt_1"."def_b9ce20c4d0e01093",
FALSE ) OR COALESCE( "qt_2"."def_c23d0c3ff14cd87e",
FALSE ) )
THEN ( (
CASE
WHEN COALESCE( "qt_2"."def_c23d0c3ff14cd87e",
FALSE )
THEN COALESCE( "qt_2"."c_c23d0c3ff14cd87e",
0 )
ELSE 0
END ) + (
CASE
WHEN COALESCE( "qt"."def_6dcd11732b172caa",
FALSE )
THEN COALESCE( "qt"."c_6dcd11732b172caa",
0 )
ELSE 0
END ) + (
CASE
WHEN COALESCE( "qt_1"."def_b9ce20c4d0e01093",
FALSE )
THEN COALESCE( "qt_1"."c_b9ce20c4d0e01093",
0 )
ELSE 0
END ) )
ELSE 0
END ) )
THEN 0
END ) ) IS NOT NULL ) AS "def_494017f656057f9d"
FROM ( ( ( ( "f_aw_stats_aaehbh2uk3adif6"
INNER JOIN "f_campaign_aac91czox0avdri" ON ( "f_aw_stats_aaehbh2uk3adif6"."campaign_id" = "f_campaign_aac91czox0avdri"."id" ) ) LEFT OUTER
JOIN "qt_9f075709d6d11e31a4781fb9ac741f4f" AS "qt" ON ( "f_aw_stats_aaehbh2uk3adif6"."campaign_id" = "qt"."a_12529" ) ) LEFT OUTER
JOIN "qt_2086e7088f09d6ce0e2b59e06a739683" AS "qt_1" ON ( "f_aw_stats_aaehbh2uk3adif6"."campaign_id" = "qt_1"."a_12529" ) ) LEFT OUTER
JOIN "qt_8ed826ab67df664accc6de2588cdebe8" AS "qt_2" ON ( "f_aw_stats_aaehbh2uk3adif6"."campaign_id" = "qt_2"."a_12529" ) )
WHERE ( ( "f_campaign_aac91czox0avdri"."agency_id" IN ( 103127 ) )
AND ( "f_campaign_aac91czox0avdri"."status_id" IN ( 1497088 ) )
AND ( 0 = (
CASE
WHEN ( ( "f_campaign_aac91czox0avdri"."agency_id" IN ( 103127 ) )
AND ( "f_campaign_aac91czox0avdri"."status_id" IN ( 1497088 ) )
AND ( COALESCE( "qt"."def_6dcd11732b172caa",
FALSE ) OR COALESCE( "qt_1"."def_b9ce20c4d0e01093",
FALSE ) OR COALESCE( "qt_2"."def_c23d0c3ff14cd87e",
FALSE ) ) )
THEN ( (
CASE
WHEN COALESCE( "qt_2"."def_c23d0c3ff14cd87e",
FALSE )
THEN COALESCE( "qt_2"."c_c23d0c3ff14cd87e",
0 )
ELSE 0
END ) + (
CASE
WHEN COALESCE( "qt"."def_6dcd11732b172caa",
FALSE )
THEN COALESCE( "qt"."c_6dcd11732b172caa",
0 )
ELSE 0
END ) + (
CASE
WHEN COALESCE( "qt_1"."def_b9ce20c4d0e01093",
FALSE )
THEN COALESCE( "qt_1"."c_b9ce20c4d0e01093",
0 )
ELSE 0
END ) )
ELSE 0
END ) )
AND ( 42264 = "f_aw_stats_aaehbh2uk3adif6"."dt_b_workrecorded_id" ) )
GROUP BY 1,
2,
3,
4,
5 )
ANALYZE "qt_22d49b093abb2e140390ccf0721e45ef"
CREATE TABLE "qt_4e941140401bcbd3ddb5d14549b3b2c8" AS (
SELECT COALESCE( "qt"."a_12533",
"qt_1"."a_12533",
"qt_2"."a_12533" ) AS "a_12533",
COALESCE( "qt"."a_12537",
"qt_1"."a_12537",
"qt_2"."a_12537" ) AS "a_12537",
COALESCE( "qt"."a_12539",
"qt_1"."a_12539",
"qt_2"."a_12539" ) AS "a_12539",
COALESCE( "qt"."a_81994",
"qt_1"."a_81994",
"qt_2"."a_81994" ) AS "a_81994",
COALESCE( "qt"."a_81997",
"qt_1"."a_81997",
"qt_2"."a_81997" ) AS "a_81997",
( (
CASE
WHEN COALESCE( "qt"."def_494017f656057f9d",
FALSE )
THEN COALESCE( "qt"."c_494017f656057f9d",
0 )
ELSE 0
END ) + (
CASE
WHEN COALESCE( "qt_2"."def_8d6c86be281e79ef",
FALSE )
THEN COALESCE( "qt_2"."c_8d6c86be281e79ef",
0 )
ELSE 0
END ) + (
CASE
WHEN COALESCE( "qt_1"."def_4c0b2b88e2f8f6df",
FALSE )
THEN COALESCE( "qt_1"."c_4c0b2b88e2f8f6df",
0 )
ELSE 0
END ) ) AS "m_29631"
FROM ( ( "qt_22d49b093abb2e140390ccf0721e45ef" AS "qt" FULL OUTER
JOIN "qt_7560edd32aa829ea57440233df2c9f0e" AS "qt_1" ON ( ( "qt"."a_81997" = "qt_1"."a_81997" )
AND ( "qt"."a_12539" = "qt_1"."a_12539" )
AND ( "qt"."a_12533" = "qt_1"."a_12533" )
AND ( "qt"."a_12537" = "qt_1"."a_12537" )
AND ( "qt"."a_81994" = "qt_1"."a_81994" ) ) ) FULL OUTER
JOIN "qt_f792eab9de23c56d439335bdf8ecbcb1" AS "qt_2" ON ( ( COALESCE( "qt"."a_81997",
"qt_1"."a_81997" ) = "qt_2"."a_81997" )
AND ( COALESCE( "qt"."a_12539",
"qt_1"."a_12539" ) = "qt_2"."a_12539" )
AND ( COALESCE( "qt"."a_12533",
"qt_1"."a_12533" ) = "qt_2"."a_12533" )
AND ( COALESCE( "qt"."a_12537",
"qt_1"."a_12537" ) = "qt_2"."a_12537" )
AND ( COALESCE( "qt"."a_81994",
"qt_1"."a_81994" ) = "qt_2"."a_81994" ) ) )
WHERE ( COALESCE( "qt"."def_494017f656057f9d",
FALSE ) OR COALESCE( "qt_1"."def_4c0b2b88e2f8f6df",
FALSE ) OR COALESCE( "qt_2"."def_8d6c86be281e79ef",
FALSE ) ) )
ANALYZE "qt_4e941140401bcbd3ddb5d14549b3b2c8"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment