修复sql问题
This commit is contained in:
parent
e1c1ad75d4
commit
20af299076
@ -1,41 +1,56 @@
|
||||
from utils.read_sql_files import read_one_game_sql_files
|
||||
from utils.execute_sql import select_execute_sql
|
||||
|
||||
from utils.read_sql_files import read_sql_files
|
||||
|
||||
|
||||
def dim(game_information):
|
||||
read_one_game_sql_files('dim',game_information)
|
||||
read_one_game_sql_files('dim', game_information)
|
||||
|
||||
|
||||
def dwd(game_information):
|
||||
read_one_game_sql_files('dwd_before',game_information)
|
||||
read_one_game_sql_files('dwd_after',game_information)
|
||||
read_one_game_sql_files('dwd_before', game_information)
|
||||
read_one_game_sql_files('dwd_after', game_information)
|
||||
|
||||
|
||||
def dws(game_information):
|
||||
read_one_game_sql_files('dws_before',game_information)
|
||||
read_one_game_sql_files('dws_after',game_information)
|
||||
read_one_game_sql_files('dws_before', game_information)
|
||||
read_one_game_sql_files('dws_after', game_information)
|
||||
|
||||
|
||||
def ads(game_information):
|
||||
read_one_game_sql_files('ads',game_information)
|
||||
read_one_game_sql_files('ads', game_information)
|
||||
|
||||
|
||||
def job_one_game():
|
||||
sql_params = "49,50,51"
|
||||
|
||||
sql_str = f"select relation_id,game_channel_id,game_identity,game_platform_id from dim.game_product_relation where relation_id IN ({sql_params})"
|
||||
game_information = select_execute_sql(sql_str)
|
||||
for game in game_information:
|
||||
game_information_dic = {
|
||||
"${relation_id}": str(game[0]),
|
||||
"${channel_id}": str(game[1]),
|
||||
"${game_identity}": game[2],
|
||||
"${platform_id}": str(game[3])
|
||||
}
|
||||
print(game_information_dic)
|
||||
# dim(game_information_dic)
|
||||
# dwd(game_information_dic)
|
||||
# dws(game_information_dic)
|
||||
# ads(game_information_dic)
|
||||
|
||||
|
||||
def rerun():
|
||||
# read_sql_files('dim')
|
||||
|
||||
read_sql_files('dwd_before')
|
||||
read_sql_files('dwd_after')
|
||||
|
||||
read_sql_files('dws_before')
|
||||
read_sql_files('dws_after')
|
||||
|
||||
read_sql_files('ads')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
sql_params="49,50,51"
|
||||
|
||||
sql_str=f"select relation_id,game_channel_id,game_identity,game_platform_id from dim.game_product_relation where relation_id IN ({sql_params})"
|
||||
game_information=select_execute_sql(sql_str)
|
||||
for game in game_information:
|
||||
game_information_dic={
|
||||
"${relation_id}": str(game[0]),
|
||||
"${channel_id}": str(game[1]),
|
||||
"${game_identity}": game[2],
|
||||
"${platform_id}": str(game[3])
|
||||
}
|
||||
print(game_information_dic)
|
||||
# dim(game_information_dic)
|
||||
# dwd(game_information_dic)
|
||||
# dws(game_information_dic)
|
||||
# ads(game_information_dic)
|
||||
rerun()
|
||||
|
@ -29,6 +29,8 @@ def read_sql_files(directory, day):
|
||||
log.error(f"读取文件 {directory} 时出现错误: {e}")
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# 遍历300到0
|
||||
for day in range(301):
|
||||
|
@ -9,7 +9,7 @@ SELECT
|
||||
t1.ds,
|
||||
COUNT(DISTINCT t1.user_id) AS num,
|
||||
COALESCE(SUM(pay_amount),0) order_amount,
|
||||
SUM(CASE WHEN (t2.ds_date-t1.ds_date) <= 0 THEN pay_amount ELSE 0 END) AS ltv0,
|
||||
SUM(CASE WHEN t2.ds_date=t1.ds_date THEN pay_amount ELSE 0 END) AS ltv0,
|
||||
SUM(CASE WHEN (t2.ds_date-t1.ds_date) <= 1 THEN pay_amount ELSE 0 END) AS ltv1,
|
||||
SUM(CASE WHEN (t2.ds_date-t1.ds_date) <= 2 THEN pay_amount ELSE 0 END) AS ltv2,
|
||||
SUM(CASE WHEN (t2.ds_date-t1.ds_date) <= 3 THEN pay_amount ELSE 0 END) AS ltv3,
|
||||
@ -30,7 +30,7 @@ LEFT JOIN
|
||||
ON
|
||||
t1.relation_id = t2.relation_id
|
||||
AND t1.user_id = t2.user_id
|
||||
AND t2.ds_date-t1.ds_date IN (1,2,3,4,5,6,7,14,30,60,90,150,300)
|
||||
AND t2.ds_date-t1.ds_date IN (0,1,2,3,4,5,6,7,14,30,60,90,150,300)
|
||||
where t1.ds>='${300_days_later}'
|
||||
GROUP BY
|
||||
t1.relation_id, t1.prodid, t1.ds
|
||||
|
@ -1,33 +1,5 @@
|
||||
-- 取登陆最早时间 逻辑:如果之前没出现过,那插入这条记录做最早用户登陆时间
|
||||
-- 首次写入数据sql
|
||||
-- INSERT INTO dim.first_user(game_channel_id,game_identity,game_platform_id,relation_id,prodid,user_id,ds,ds_date)
|
||||
-- WITH active_account_tmp AS (
|
||||
-- SELECT distinct
|
||||
-- t1.channel_id,
|
||||
-- t1.game_identity,
|
||||
-- t1.platform_id,
|
||||
-- t1.user_id,
|
||||
-- '${bizdate}' AS ds -- 直接赋值替代min(ds)
|
||||
-- FROM ods.active_account_list t1
|
||||
-- WHERE t1.ds = '${bizdate}'
|
||||
-- )
|
||||
-- SELECT t2.game_channel_id
|
||||
-- ,t2.game_identity
|
||||
-- ,t2.game_platform_id
|
||||
-- ,t2.relation_id
|
||||
-- ,t2.product_id prodid
|
||||
-- ,t1.user_id
|
||||
-- ,t1.ds ds
|
||||
-- ,'${biz-date}' ds_date
|
||||
-- FROM active_account_tmp 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
|
||||
-- ON CONFLICT (relation_id, user_id)
|
||||
-- DO NOTHING;
|
||||
|
||||
INSERT INTO dim.first_user(game_channel_id,game_identity,game_platform_id,relation_id,prodid,user_id,ds,ds_date)
|
||||
WITH active_account_tmp AS (
|
||||
SELECT distinct
|
||||
|
Loading…
x
Reference in New Issue
Block a user