-- 增量脚本：为exams表增加三轮得分字段
-- 创建时间：2025-10-12
-- 说明：简化三轮考试机制，一条考试记录存储三轮得分

USE kaopeilian;

-- 1. 为exams表增加三轮得分字段
ALTER TABLE exams 
  ADD COLUMN round1_score FLOAT NULL COMMENT '第一轮得分' AFTER score,
  ADD COLUMN round2_score FLOAT NULL COMMENT '第二轮得分' AFTER round1_score,
  ADD COLUMN round3_score FLOAT NULL COMMENT '第三轮得分' AFTER round2_score;

-- 2. 为已存在的考试记录设置默认值（将score复制到round1_score）
UPDATE exams 
SET round1_score = score 
WHERE score IS NOT NULL AND round1_score IS NULL;

-- 3. 验证结果
SELECT 
    COUNT(*) as total_exams,
    COUNT(round1_score) as has_round1,
    COUNT(round2_score) as has_round2,
    COUNT(round3_score) as has_round3
FROM exams;

-- 输出结果示例
SELECT 
    id, 
    exam_name, 
    score, 
    round1_score, 
    round2_score, 
    round3_score 
FROM exams 
LIMIT 5;

