需要协助!
我有2个表:Employee (Per_Code, Per_Name, Dept_Name)
| Task (Dest_ID, Destination, Salary)
作为数据源。
现在我制作另一张表Employee_Salary (Per_Code, Per_Name, Dept_Name, Dest_ID, Destination, Date, Duration, Salary)
。
我的SQL声明:
INSERT INTO Employee_Salary (Per_Code, Per_Name, Dept_Name, Dest_ID, Destination, Date, Duration, Salary)
VALUES (
'1001',
(SELECT Per_Name FROM Employee WHERE Per_Code=1001),
(SELECT Dept_Name FROM Employee WHERE Per_Code=1001),
(SELECT Dest_ID FROM Task WHERE Destination="CityA"),
'CityA',
'2014-07-07',
'3',
(SELECT Salary FROM Task WHERE Destination="CityA")
);
但它说“查询输入必须包含至少一个表或查询”。我的SQL语句是错的吗?请帮帮我......任何人!
答案 0 :(得分:-2)
可能是这样的东西
INSERT INTO Employee_Salary
(Per_Code, Per_Name, Dept_Name, Dest_ID, Destination, Date, Duration, Salary)
SELECT '1001',E.Per_Name,E.Dept_Name,T.Dest_ID,'CityA','2014-07-07','3',T.Salary
From Employee E CROSS JOIN Task T
WHERE E.Per_Code=1001 AND T.Destination='CityA'
或者:
INSERT INTO Employee_Salary
(Per_Code, Per_Name, Dept_Name, Dest_ID, Destination, Date, Duration, Salary)
SELECT '1001',E.Per_Name,E.Dept_Name,T.Dest_ID,'CityA','2014-07-07','3',T.Salary
From Employee E,Task T
WHERE E.Per_Code=1001 AND T.Destination='CityA'