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

63 lines
1.3 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.

-- ==================== 修复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;