select
index_name
, is_fc
, goal_value
, index_value
, gap_goal
, top_gap_city
, top_gap_store
, top_gap_cate
, top_gap_item
,sum(a) as abc
from (
select
index_name
, is_fc
, goal_value
, index_value
, gap_goal
, top_gap_city
, top_gap_store
, top_gap_cate
, top_gap_item
, '1' as a --
from cn_ads_dev_dl_tmp.ads_sc_repl_cloud_monitor_recap_fc_df_tmp501 -- 新数据
union all
select
index_name
, is_fc
, goal_value
, index_value
, gap_goal
, top_gap_city
, top_gap_store
, top_gap_cate
, top_gap_item
,'-1' as a
from cn_ads_dev_dl_tables.ads_sc_repl_cloud_monitor_recap_df where ts = '2024-04-23' -- 旧数据
) tmp
group by
index_name
, is_fc
, goal_value
, index_value
, gap_goal
, top_gap_city
, top_gap_store
, top_gap_cate
, top_gap_item
having sum(a)<>0 ;