data_job/sql/ads/data_screen.sql
2025-03-04 10:24:36 +08:00

35 lines
1.1 KiB
SQL

-- 数据概览
INSERT INTO ads.data_screen(relation_id,prodid,ds,ds_type,ds_name,order_amount,money,processed_amount,"cost")
SELECT t1.relation_id
,t1.product_id prodid
,t.ds
,t.ds_type
,t.ds_name
,SUM(t.order_amount) order_amount
,SUM(t2.money) money
,0 processed_amount
,SUM(COALESCE(t3.cost,0)) AS "cost"
FROM dwd.order_df t
INNER JOIN dim.game_product_relation t1
ON t.game_channel_id = t1.game_channel_id
AND t.game_identity = t1.game_identity
AND t.game_platform_id = t1.game_platform_id
INNER JOIN dwd.revenue_df t2 on t1.relation_id=t2.relation_id
AND t.ds=t2.ds
and t.ds_type=t2.ds_type
left join "ads"."ad_data" t3
on t1.relation_id=t3.relation_id
and t.ds=t3.ds
and t.ds_type=t3.ds_type
GROUP BY t1.relation_id
,t1.product_id
,t.ds
,t.ds_type
,t.ds_name
ON CONFLICT (relation_id,ds,ds_type) DO
UPDATE SET prodid = EXCLUDED.prodid,order_amount = EXCLUDED.order_amount,money = EXCLUDED.money
,processed_amount = EXCLUDED.processed_amount,"cost" = EXCLUDED."cost"
;