Files
bl/help/内测奖励查询.sql

42 lines
2.5 KiB
Go
Raw Normal View History

-- 整合所有用户核心指标任务数击杀数在线时长胜利数最高关卡最高刷新关卡
SELECT
COALESCE(t1.player_id, t2.player_id, t3.player_id, t4.player_id, t5.player_id, t6.player_id) AS player_id,
-- 处理NULL值无数据时显示0
COALESCE(t1.task_count, 0) AS task_count, -- player_task表的任务数量
COALESCE(t2.catch_kill_count, 0) AS catch_kill_count, -- player_catch_kill_count表的击杀数量
COALESCE(t3.online_time, 0) AS online_time, -- 在线时长
COALESCE(t4.mess_win, 0) AS mess_win, -- 胜利次数
COALESCE(t5.max_stage, 0) AS max_stage, -- 最高关卡
COALESCE(t6.max_fresh_stage, 0) AS max_fresh_stage -- 最高刷新关卡
FROM
-- 子查询1统计player_task表的用户任务数
(SELECT player_id, COUNT(*) AS task_count
FROM player_task
GROUP BY player_id) t1
FULL OUTER JOIN
-- 子查询2统计player_catch_kill_count表的用户击杀数
(SELECT player_id, COUNT(*) AS catch_kill_count
FROM player_catch_kill_count
GROUP BY player_id) t2 ON t1.player_id = t2.player_id
FULL OUTER JOIN
-- 子查询3提取player_info表的在线时长>0
(SELECT player_id, (data->>'online_time')::int AS online_time
FROM player_info
WHERE jsonb_exists(data, 'online_time') AND (data->>'online_time')::int > 0) t3 ON COALESCE(t1.player_id, t2.player_id) = t3.player_id
FULL OUTER JOIN
-- 子查询4提取player_info表的胜利次数mess_win >0
(SELECT player_id, (data->>'mess_win')::int AS mess_win
FROM player_info
WHERE jsonb_exists(data, 'mess_win') AND (data->>'mess_win')::int > 0) t4 ON COALESCE(t1.player_id, t2.player_id, t3.player_id) = t4.player_id
FULL OUTER JOIN
-- 子查询5提取player_info表的最高关卡max_stage >0
(SELECT player_id, (data->>'max_stage')::int AS max_stage
FROM player_info
WHERE jsonb_exists(data, 'max_stage') AND (data->>'max_stage')::int > 0) t5 ON COALESCE(t1.player_id, t2.player_id, t3.player_id, t4.player_id) = t5.player_id
FULL OUTER JOIN
-- 子查询6提取player_info表的最高刷新关卡max_fresh_stage >0
(SELECT player_id, (data->>'max_fresh_stage')::int AS max_fresh_stage
FROM player_info
WHERE jsonb_exists(data, 'max_fresh_stage') AND (data->>'max_fresh_stage')::int > 0) t6 ON COALESCE(t1.player_id, t2.player_id, t3.player_id, t4.player_id, t5.player_id) = t6.player_id
-- 可选按某一指标排序比如在线时长降序
ORDER BY online_time DESC;