-- ============================================
-- 为 testuser 添加考试记录
-- ============================================

USE `kaopeilian`;

-- 设置 testuser 的 ID
SET @test_user_id = 1;

-- 获取第一个课程ID（Python基础课程）
SET @course_id = 4;

-- 添加考试记录（exams 表是用户的考试实例）
INSERT INTO exams (
    user_id, 
    course_id, 
    exam_name, 
    question_count, 
    total_score, 
    pass_score, 
    start_time, 
    end_time, 
    duration_minutes, 
    score, 
    is_passed, 
    status,
    questions,
    answers
) VALUES
-- 第一次考试（15天前）
(@test_user_id, @course_id, 'Python基础测试-第1次', 20, 100, 60, 
 '2025-09-07 10:00:00', '2025-09-07 10:50:00', 50, 72, 1, 'completed',
 '[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]',
 '{"1":"A","2":"B","3":"A","4":"C","5":"A","6":"B","7":"A","8":"D","9":"A","10":"B","11":"A","12":"C","13":"A","14":"B","15":"A","16":"C","17":"A","18":"B","19":"A","20":"D"}'),

-- 第二次考试（10天前）
(@test_user_id, @course_id, 'Python基础测试-第2次', 20, 100, 60, 
 '2025-09-12 14:00:00', '2025-09-12 14:45:00', 45, 85, 1, 'completed',
 '[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]',
 '{"1":"A","2":"A","3":"A","4":"A","5":"A","6":"B","7":"A","8":"A","9":"A","10":"B","11":"A","12":"A","13":"A","14":"B","15":"A","16":"A","17":"A","18":"B","19":"A","20":"A"}'),

-- 第三次考试（5天前）
(@test_user_id, @course_id, 'Python进阶测试', 25, 100, 70, 
 '2025-09-17 09:00:00', '2025-09-17 10:15:00', 75, 78, 1, 'completed',
 '[21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45]',
 '{"21":"A","22":"B","23":"A","24":"C","25":"A","26":"B","27":"A","28":"D","29":"A","30":"B","31":"A","32":"C","33":"A","34":"B","35":"A","36":"C","37":"A","38":"B","39":"A","40":"D","41":"A","42":"B","43":"A","44":"C","45":"A"}'),

-- 第四次考试（3天前）
(@test_user_id, @course_id, 'Python项目实战测试', 30, 100, 80, 
 '2025-09-19 13:30:00', '2025-09-19 15:00:00', 90, 92, 1, 'completed',
 '[46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75]',
 '{"46":"A","47":"A","48":"A","49":"A","50":"A","51":"B","52":"A","53":"A","54":"A","55":"B","56":"A","57":"A","58":"A","59":"B","60":"A","61":"A","62":"A","63":"B","64":"A","65":"A","66":"A","67":"A","68":"A","69":"A","70":"A","71":"B","72":"A","73":"A","74":"A","75":"A"}'),

-- 最近的考试（昨天）
(@test_user_id, @course_id, 'Python综合测试', 50, 100, 85, 
 '2025-09-21 10:00:00', '2025-09-21 11:50:00', 110, 95, 1, 'completed',
 '[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50]',
 '{"1":"A","2":"A","3":"A","4":"A","5":"A","6":"A","7":"A","8":"A","9":"A","10":"A","11":"A","12":"A","13":"A","14":"A","15":"A","16":"A","17":"A","18":"A","19":"A","20":"A","21":"A","22":"A","23":"A","24":"A","25":"A","26":"B","27":"A","28":"A","29":"A","30":"B","31":"A","32":"A","33":"A","34":"B","35":"A","36":"A","37":"A","38":"B","39":"A","40":"A","41":"A","42":"B","43":"A","44":"A","45":"A","46":"A","47":"A","48":"A","49":"A","50":"A"}');

-- 如果需要添加答题详情（exam_results 表），可以根据需要补充
-- 这里简化处理，因为统计接口主要用 exams 表的数据

-- 查询验证
SELECT 
    COUNT(*) as exam_count,
    ROUND(AVG(score), 1) as avg_score,
    MIN(score) as min_score,
    MAX(score) as max_score
FROM exams 
WHERE user_id = @test_user_id AND status = 'completed';

-- 计算总练习题数（所有考试的题目总和）
SELECT 
    SUM(question_count) as total_practice_questions
FROM exams 
WHERE user_id = @test_user_id AND status = 'completed';

SELECT '考试数据添加完成！' as message;
