2016-09-19 71 views
-2

我在Microsoft Access中有2个表。需要帮助查找2个表之间的数据

1表名 - 在第一个表的代码

我有超过15列,我需要插入10列一列后,和标题命名为“类型” - 详细介绍 第二表名。第二个表中的 我有5栏。

每个表中的常见列是分析代码。

表1

+-------+-------+---------------+------------+---------+ 
| Test1 | test2 | Analysis code | test4 | test5 | 
+-------+-------+---------------+------------+---------+ 
| ab | dfd | TON   | fddafd  | 212132 | 
| ced | fd | SIN   | 2133  | dfd2fd1 | 
| ef | fdfd | TON   | df2df1d31f | dfd3sa3 | 
| gh | dfd | SIN   | dfd63  | c22  | 
+-------+-------+---------------+------------+---------+ 

表2

+----------+---------------+----------+------------------------+ 
| sample 1 | Analysis code | sample 3 |   Type   | 
+----------+---------------+----------+------------------------+ 
| 558825 | TON   | a  | Terminated on network | 
| 258c  | SIN   | b  | International network | 
| 5856c | TOF   | c  | Terminated off network | 
| a21c5b | SMS   | d  | text message   | 
+----------+---------------+----------+------------------------+  

OUT PUT表

+-------+-------+---------------+-----------------------+------------+---------+ 
| Test1 | test2 | Analysis code |   Type   | test4 | test5 | 
+-------+-------+---------------+-----------------------+------------+---------+ 
| ab | dfd | TON   | Terminated on network | fddafd  | 212132 | 
| ced | fd | SIN   | International network | 2133  | dfd2fd1 | 
| ef | fdfd | TON   | Terminated on network | df2df1d31f | dfd3sa3 | 
| gh | dfd | SIN   | International network | dfd63  | c22  | 
+-------+-------+---------------+-----------------------+------------+---------+ 
+3

使用格式化工具为了使您的文章更“可读”,我什至不知道你的问题。 – LostReality

+0

http://ozh.github.io/ascii-tables/查看样本数据。 – Andre

回答

0

你需要加入相应的列在表1和表2。在你的情况“分析代码”

的样本是:

SELECT Test1, test2, [table1.Analysis code], table2.type .... rest 
FROM table1 left join table2 on table1.[Analysis code] = tble2.[analysis code] 

上面的SQL代码将产生[有些]您的预计产出表。话虽如此,请允许我建议,您需要阅读更多关于SQL语言和[关系数据库]的信息。将帮助你更多!

+0

在上面的例子中,我只给出了5列,但我有超过20列,在这种情况下,我是否需要更新表1中的所有列名称,替换上面的代码右边的其余部分... 如果你不介意,你可以请完成上面的代码,而不更新那里的其余部分,这样我就可以在Access中得到一些关于我的数据库的想法。请做有需要的人。谢谢。 – Giri