28 lines
1.1 KiB
SQL
28 lines
1.1 KiB
SQL
-- 取登陆最早时间 逻辑:如果之前没出现过,那插入这条记录做最早用户登陆时间
|
|
-- 首次写入数据sql
|
|
INSERT INTO dim.first_user(game_channel_id,game_identity,game_platform_id,relation_id,prodid,user_id,ds)
|
|
SELECT t2.game_channel_id
|
|
,t2.game_identity
|
|
,t2.game_platform_id
|
|
,t2.relation_id
|
|
,t2.product_id prodid
|
|
,t1.user_id
|
|
,min(ds) ds
|
|
FROM ods.active_account_list t1
|
|
inner join
|
|
dim.game_product_relation t2
|
|
ON t1.channel_id = t2.game_channel_id
|
|
AND t1.game_identity = t2.game_identity
|
|
AND t1.platform_id = t2.game_platform_id
|
|
where ds>='${30_days_later}' and t1.channel_id='${channel_id}' AND t1.game_identity='${game_identity}' AND t1.platform_id='${platform_id}'
|
|
GROUP BY t2.game_channel_id
|
|
,t2.game_identity
|
|
,t2.game_platform_id
|
|
,t2.relation_id
|
|
,t2.product_id
|
|
,t1.user_id
|
|
|
|
ON CONFLICT (relation_id,user_id)
|
|
DO UPDATE SET game_channel_id = EXCLUDED.game_channel_id,game_identity = EXCLUDED.game_identity ,game_platform_id = EXCLUDED.game_platform_id
|
|
,prodid = EXCLUDED.prodid,user_id = EXCLUDED.user_id,ds = EXCLUDED.ds
|
|
; |