-- 调试检查脚本
USE martial_db;

-- 检查参赛者的project_id是否都有对应的项目
SELECT
    '检查参赛者项目关联' AS check_item,
    a.id,
    a.project_id,
    a.player_name,
    p.id AS project_exists,
    p.project_name,
    p.type AS project_type
FROM martial_athlete a
LEFT JOIN martial_project p ON a.project_id = p.id
WHERE a.competition_id = 200
LIMIT 10;

-- 检查是否有参赛者的project_id为NULL或找不到对应项目
SELECT
    '检查异常数据' AS check_item,
    COUNT(*) AS total_athletes,
    SUM(CASE WHEN project_id IS NULL THEN 1 ELSE 0 END) AS null_project_id,
    SUM(CASE WHEN p.id IS NULL THEN 1 ELSE 0 END) AS project_not_found
FROM martial_athlete a
LEFT JOIN martial_project p ON a.project_id = p.id
WHERE a.competition_id = 200;
