-- ===================================================== -- 为用户"道玄"(uid=121)添加观看历史数据 -- ===================================================== -- 1. 确保表存在 CREATE TABLE IF NOT EXISTS `eb_view_history` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `user_id` int(11) NOT NULL, `target_type` varchar(20) NOT NULL, `target_id` varchar(50) NOT NULL, `target_title` varchar(255) DEFAULT NULL, `view_duration` int(11) DEFAULT 0, `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `idx_user_id` (`user_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; -- 2. 插入观看历史数据 INSERT INTO eb_view_history (user_id, target_type, target_id, target_title, view_duration, create_time, update_time) VALUES (121, 'room', '1', '欢乐游戏直播', 1800, NOW() - INTERVAL 1 HOUR, NOW() - INTERVAL 1 HOUR), (121, 'room', '2', '音乐分享会', 2400, NOW() - INTERVAL 2 HOUR, NOW() - INTERVAL 2 HOUR), (121, 'room', '8', '火影忍者', 3600, NOW() - INTERVAL 30 MINUTE, NOW() - INTERVAL 30 MINUTE); -- 3. 验证结果 SELECT * FROM eb_view_history WHERE user_id = 121 ORDER BY update_time DESC;