guoyu/fix_206_class.sql
2025-12-11 23:28:07 +08:00

41 lines
1.0 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- ========================================
-- 修复编号206的班级数据
-- 只保留最新的班级高级班1班其他设为status=0
-- ========================================
-- 第一步:确认当前数据
SELECT
sc.id,
sc.student_id,
sc.class_id,
c.class_name,
sc.status,
sc.join_time
FROM student_class sc
LEFT JOIN class c ON sc.class_id = c.id
WHERE sc.student_id = 206
ORDER BY sc.join_time DESC;
-- 第二步执行修复将旧班级设为status=0
-- ⚠️ 确认上面查询结果后再执行这条!
UPDATE student_class
SET status = 0
WHERE student_id = 206
AND status = 1
AND id IN (4472, 4443); -- 中级班1班、初级班1班
-- 第三步:验证修复结果
SELECT
sc.id,
sc.student_id,
sc.class_id,
c.class_name,
sc.status,
sc.join_time
FROM student_class sc
LEFT JOIN class c ON sc.class_id = c.id
WHERE sc.student_id = 206
ORDER BY sc.status DESC, sc.join_time DESC;
-- 应该只有一条status=1的记录高级班1班