0
  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。是不是有点不对劲?我收到此错误消息

1241 - 操作数应包含 1 列

4

3 回答 3

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)
于 2013-02-07T10:37:11.610 回答
1

尝试使用INSERT INTO...SELECT..FROM而不是INSERT INTO..VALUES. 您可以将null值包含为列。

您还缺少JOINtable 的条件employee_details ep。您还需要添加:

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
INNER JOIN project_tracker pt
  ON p.project_tracker_id = pt.project_tracker_id
INNER JOIN project_quota_details pqd
  ON p.project_id = pqd.project_id
INNER JOIN specialty sp
  ON pqd.specialty_id = sp.specialty_id
INNER JOIN employee_details ep
  ON       --- add join condition here for this table
于 2013-02-07T10:30:39.960 回答
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
于 2013-02-07T10:30:28.150 回答