插入日期列值尚不存在的位置
Insert into where date column value doesn't already exist
我有以下查询,我想创建一个 table new_table
然后每天 INSERT INTO new_table
检查日期是否存在于 date_final 中,如果它不加载这些行。
第一个 COALESCE 行有 3 个值 (p_date, c_date, t_date
),每个值都是从不同 table 的 CTE 创建的,每天加载一个日期。
INSERT INTO my_table(
SELECT
COALESCE (p_date, c_date, t_date) AS date_final,
COALESCE (p_name,cl_name,c_name) AS brand
FROM p
FULL JOIN clicks ON cli.c_date = PAGES.p_date
FULL JOIN comm_agg ON comm_agg.t_date = p.p_date
LEFT JOIN ga ON ga.date_f = p.p_date
)
where date_final dates do not already exist in the new_table
在 new_table 中的意思是,如果 date_final 已经有日期 2/12、2/14 那么我想确保在插入时我想确保我不重新-加载那些日期
INSERT INTO my_table
SELECT
COALESCE (p_date, c_date, t_date) AS date_final,
COALESCE (p_name,cl_name,c_name) AS brand
FROM p
FULL JOIN clicks ON cli.c_date = PAGES.p_date
FULL JOIN comm_agg ON comm_agg.t_date = p.p_date
LEFT JOIN ga ON ga.date_f = p.p_date
where COALESCE (p_date, c_date, t_date) is null
我有以下查询,我想创建一个 table new_table
然后每天 INSERT INTO new_table
检查日期是否存在于 date_final 中,如果它不加载这些行。
第一个 COALESCE 行有 3 个值 (p_date, c_date, t_date
),每个值都是从不同 table 的 CTE 创建的,每天加载一个日期。
INSERT INTO my_table(
SELECT
COALESCE (p_date, c_date, t_date) AS date_final,
COALESCE (p_name,cl_name,c_name) AS brand
FROM p
FULL JOIN clicks ON cli.c_date = PAGES.p_date
FULL JOIN comm_agg ON comm_agg.t_date = p.p_date
LEFT JOIN ga ON ga.date_f = p.p_date
)
where date_final dates do not already exist in the new_table
在 new_table 中的意思是,如果 date_final 已经有日期 2/12、2/14 那么我想确保在插入时我想确保我不重新-加载那些日期
INSERT INTO my_table
SELECT
COALESCE (p_date, c_date, t_date) AS date_final,
COALESCE (p_name,cl_name,c_name) AS brand
FROM p
FULL JOIN clicks ON cli.c_date = PAGES.p_date
FULL JOIN comm_agg ON comm_agg.t_date = p.p_date
LEFT JOIN ga ON ga.date_f = p.p_date
where COALESCE (p_date, c_date, t_date) is null