INSERT INTO project_dim
(project_id,
project_name,
client_name,
list_type,
project_start_date,
project_create_date,
actual_project_end_date,
scheduled_end_date,
created_by,
project_manager,
project_specialty,
quota_country,
quota,
create_date,
update_date)
VALUES ( (SELECT p.project_id,
p.project_name,
p.client_name,
p.list_type,
pt.project_start_date,
Date(p.created_date),
pt.actual_completion_date,
pt.scheduled_completion_date,
p.created_by,
Concat(ep.first_name, ' ', ep.last_name),
sp.specialty_name,
pqd.country,
pqd.quota
FROM project_details p,
project_tracker pt,
employee_details ep,
specialty sp,
project_quota_details pqd
WHERE p.project_tracker_id = pt.project_tracker_id
AND p.project_id = pqd.project_id
AND pqd.specialty_id = sp.specialty_id),
NULL,
NULL )
我在select语句的值之后插入null,null。这有点不对吗?我收到此错误消息
答案 0 :(得分:1)
尝试使用INSERT INTO...SELECT..FROM
代替INSERT INTO..VALUES
。您可以将null
值包含在列中。
您还缺少表JOIN
的{{1}}条件。您还需要添加它:
employee_details ep
答案 1 :(得分:1)
INSERT INTO project_dim
(project_id,
project_name,
client_name,
list_type,
project_start_date,
project_create_date,
actual_project_end_date,
scheduled_end_date,
created_by,
project_manager,
project_specialty,
quota_country,
quota,
create_date,
update_date)
VALUES ( SELECT p.project_id,
p.project_name,
p.client_name,
p.list_type,
pt.project_start_date,
Date(p.created_date),
pt.actual_completion_date,
pt.scheduled_completion_date,
p.created_by,
Concat(ep.first_name, ' ', ep.last_name),
sp.specialty_name,
pqd.country,
pqd.quota,
null,
null
FROM project_details p,
project_tracker pt,
employee_details ep,
specialty sp,
project_quota_details pqd
WHERE p.project_tracker_id = pt.project_tracker_id
AND p.project_id = pqd.project_id
AND pqd.specialty_id = sp.specialty_id)
答案 2 :(得分:0)
最好删除values子句,只使用SELECT(SELECT子句中有几个空列,表示你需要的空白列。)
这样的事情: -
INSERT INTO Project_Dim
( Project_Id, Project_Name, Client_Name, List_Type, Project_Start_Date, Project_Create_Date, Actual_Project_END_Date, Scheduled_End_Date, Created_By, Project_Manager, Project_Specialty, Quota_Country, Quota, Create_Date, Update_Date
)
select p.Project_Id, p.Project_Name, p.Client_Name, p.List_Type, pt.Project_Start_Date, DATE(p.Created_Date), pt.Actual_Completion_Date, pt.Scheduled_Completion_Date, p.Created_By, CONCAT(ep.First_Name, ' ', ep.Last_Name), sp.Specialty_Name,pqd.Country,pqd.Quota, null, null from Project_Details p, Project_Tracker pt, Employee_Details ep, Specialty sp, Project_Quota_Details pqd where p.Project_Tracker_Id=pt.Project_Tracker_Id and p.Project_Id=pqd.Project_Id and pqd.Specialty_Id = sp.Specialty_Id