peixue-dev/Archive/peidu-temp-files/sql/🚀修复deleted字段-2026-01-23.sql

63 lines
1.3 KiB
MySQL
Raw Normal View History

2026-02-28 17:26:03 +08:00
-- ==================== 修复deleted字段 ====================
-- 1. 检查当前deleted字段的值
SELECT
id,
student_id,
student_name,
record_type,
record_date,
status,
deleted, -- ✅ 检查deleted字段
LEFT(content, 30) as content_preview
FROM growth_record
WHERE student_id = 1
ORDER BY record_date DESC;
-- 2. 更新所有记录的deleted字段为0未删除
UPDATE growth_record
SET deleted = 0
WHERE student_id = 1
AND (deleted IS NULL OR deleted != 0);
-- 3. 验证更新后的数据
SELECT
id,
student_id,
student_name,
record_type,
record_date,
status,
deleted,
LEFT(content, 30) as content_preview
FROM growth_record
WHERE student_id = 1
AND deleted = 0
ORDER BY record_date DESC;
-- 4. 测试查询(模拟后端查询)
SELECT COUNT(*) as total_count
FROM growth_record
WHERE student_id = 1
AND record_type = 'daily'
AND status = 1
AND deleted = 0;
-- 5. 如果count > 0说明修复成功
SELECT
id,
student_id,
student_name,
record_type,
record_date,
LEFT(content, 30) as content_preview,
status,
deleted
FROM growth_record
WHERE student_id = 1
AND record_type = 'daily'
AND status = 1
AND deleted = 0
ORDER BY record_date DESC
LIMIT 10;