将数据从C表插入到ask_questions和ask_answers表
使用以下语句将C表的数据插入到上述两张表中:
START TRANSACTION;
INSERT INTO ask_questions (user_id, category_id, title, description, price, hide, answers , status, created_at, updated_at)
SELECT user_id, category_id, question_title, question_title, 1, 1, 1, 1, created_at, updated_at FROM C;
SET @question_id = LAST_INSERT_ID();
INSERT INTO ask_answers (question_title, question_id, user_id, content, status, adopted_at, created_at, updated_at)
SELECT question_title, @question_id, 1007, answer_content, 1, NULL, created_at, updated_at FROM C;
COMMIT;
此语句将C表的数据插入到ask_questions表和ask_answers表中,并将ask_questions表生成的最新插入ID存储在@question_id变量中,以便将ask_answers表中的数据与ask_questions表中的数据关联。
原文地址: https://www.cveoy.top/t/topic/lO22 著作权归作者所有。请勿转载和采集!