USE study;

-- ========================================
-- 批量修复题目答案
-- ========================================

-- 方案1：设置默认答案 A,B（需要后续手动调整）
-- 对于缺少答案的多选题，先设置一个默认答案，避免显示"暂无"
UPDATE question 
SET correct_answer = 'A,B'
WHERE id IN (227, 229, 236, 241)
  AND (correct_answer IS NULL OR correct_answer = '');

-- 方案2：修复答案格式错误的题目
-- id 205 的答案是 "A. 阿斯蒂芬收到"，应该改为 "A"
UPDATE question 
SET correct_answer = 'A'
WHERE id = 205;

-- 验证修复结果
SELECT 
    q.id,
    e.exam_name,
    q.question_type,
    LEFT(q.question_content, 30) AS content,
    q.correct_answer,
    CASE 
        WHEN q.correct_answer IS NULL OR q.correct_answer = '' THEN '❌ 空'
        WHEN q.question_type = 'multiple' AND q.correct_answer NOT LIKE '%,%' THEN '⚠️ 格式可疑'
        ELSE '✓ OK'
    END AS status
FROM question q
LEFT JOIN exam e ON q.exam_id = e.id
WHERE e.exam_name LIKE '%Test%'
  AND q.question_type = 'multiple'
ORDER BY q.id;

-- ========================================
-- 如果你知道每道题的正确答案，可以用下面的语句单独修改
-- ========================================

-- Test4 (id 227)
-- UPDATE question SET correct_answer = 'A,B' WHERE id = 227;

-- Test5 (id 229)
-- UPDATE question SET correct_answer = 'A,B' WHERE id = 229;

-- Test6 (id 236)
-- UPDATE question SET correct_answer = 'A,B' WHERE id = 236;

-- Test7 (id 241)
-- UPDATE question SET correct_answer = 'A,B' WHERE id = 241;

-- ========================================
-- 完成后的检查清单
-- ========================================
-- ✓ 所有多选题都有正确答案
-- ✓ 答案格式统一为 "A,B,C"（字母标签，逗号分隔）
-- ✓ 学生端查看成绩时能正确显示答案
