-- 整合所有用户核心指标:任务数、击杀数、在线时长、胜利数、最高关卡、最高刷新关卡 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;