我正在使用Microsoft Office访问权限,我有一项任务是将表移出另一个表并更改列值。
我的表格如下:
ID NAME DIRECTOR UNIVERSITY
1 Banana Apple KTU
2 Pear Orange KTU
3 Tomato Cucumber VU
我还有另一个:
ID UNIVERSITY
1 KTU
2 VU
我要做的是将新表放入新文件中,如下所示:
ID NAME DIRECTOR UNIVERSITYID
1 Banana Apple 1
2 Pear Orange 1
3 Tomato Cucumber 2
我的SQL代码看起来像这样,但它并没有得到我想要的结果:
INSERT INTO Fakultetas IN 'C:\Users\NeuTronas\Desktop\NaujaDB.accdb'
SELECT DISTINCT a.[Unikalus ID] AS ID,
a.Pavadinimas AS Pavadinimas,
a.Dekanas AS Dekanas,
a.Lokacija AS Lokacija,
b.ID AS UniversitetoID
FROM Fakultetas AS a
INNER JOIN [C:\Users\NeuTronas\Desktop\NaujaDB.accdb].Universitetai AS b
ON a.Universitetas = b.Univesitetas;
这是一个有点不同的表,但如果它像一个例子,它将是:
INSERT INTO NewTableName IN 'C:\Users\NeuTronas\Desktop\NaujaDB.accdb'
SELECT DISTINCT a.ID AS ID,
a.Name AS Name,
a.Director AS Director,
a,
b.ID AS UniversityID
FROM OldTableName AS a
INNER JOIN [C:\Users\NeuTronas\Desktop\NaujaDB.accdb].SecondTableName AS b
ON a.Universitetas = b.Univesitetas;
答案 0 :(得分:0)
我不确定你在寻找什么,但你可以做以下事情:
SELECT a.ID, a.NAME, a.DIRECTOR, b.UNIVERSITYID
INTO FakultetasTemp
FROM Fakultetas a
INNER JOIN SecondTableName b
ON a.Universitetas = b.Univesitetas
答案 1 :(得分:0)
这个怎么样? 1,你复制香蕉表(我们称之为表:a)
SELECT a.* INTO a_1
FROM a;
第二次使用大学表(b)中的数据对复制的表(a1)运行更新查询
UPDATE a_1 INNER JOIN b ON a_1.University = b.UNIVERSITY SET a_1.University = [b]![Id];