我正在比较和匹配access数据库中的两个表。
Table1.column1 Table1.column2
111 111
111 112
112 112
113 112
113 113
113 113
它在另一个表上的输出应该是这样的:
Table2.column1 Table2.column2
111 111
111 (NULL)
112 112
(NULL) 112
(NULL) 112
113 113
113 113
113 (NULL)
我该怎么做呢?插入到with cast中,但不好。
发布于 2014-07-14 22:11:28
根据您的示例,您可以使用一个联合来完成此任务。但您的示例可能不会显示所有不同的情况。
select column1, column2 from Table1 where column1 = column2
union all
select column1, null from Table1 where column1 <> column2
union all
select null, column2 from Table1 where column1 <> column2
我不确定的情况是,如果你有
111 113
113 114
使用我给出的查询,它将返回
111 null
null 113
113 null
null 114
https://stackoverflow.com/questions/24732085
复制相似问题