您好我有2列 tbl_feestudent 和 tbl_feeschool ,这是他们的专栏
feestudent_id,student_id,schoolyear_id,gradelevel_id,feetype_id和feestudent_amount。
feeschool_id,schoolyear_id,gradelevel_id,feetype_id和feeschool_amount。
我使用INSERT SELECT的MySQL查询,其中 tbl_feeschool 中选择的所有项目都将插入 tbl_feestudent
tbl_feestudent 但是有其他专栏 student_id
如何将 student_id 的值插入来自 tbl_feeschool
的所有插入值我们只是说 student_id 的值 40 ,表格就像这样。
截至目前,这是我对INSERT SELECT的查询,其中WHERE schoolyear_id = 4,gradelevel_id = 1。
INSERT INTO tbl_feestudent (schoolyear_id, gradelevel_id, feetype_id, feestudent_amount)
SELECT schoolyear_id, gradelevel_id, feetype_id, feeschool_amount
FROM tbl_feeschool
WHERE schoolyear_id = 4 AND gradelevel_id = 1
答案 0 :(得分:2)
为您的选择查询添加ID
假设您的student_id为40
,那么
INSERT INTO tbl_feestudent (student_id,schoolyear_id, gradelevel_id, feetype_id, feestudent_amount)
SELECT 40,schoolyear_id, gradelevel_id, feetype_id, feeschool_amount
FROM tbl_feeschool
WHERE schoolyear_id = 4 AND gradelevel_id = 1