Sql Server 中的单元格比较? [英] Cell to Cell comparison in Sql Server?
本文介绍了Sql Server 中的单元格比较?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有 tbl1
:
Id | c1 | c2 | c3 |
____|_____|______|_______|_
1 a b c
____|_____|______|_______|_
2 h j k
____|_____|______|_______|_
3 t y u
____|_____|______|_______|_
我有 tbl2
:
Id | c1 | c2 | c3 |
____|_____|______|_______|_
1 a b D
____|_____|______|_______|_
2 c c c
____|_____|______|_______|_
3 k l k
____|_____|______|_______|_
我需要将 tbl1
中的每个单元格与 tbl2
中的适当位置进行比较:
I need to compare each cell from tbl1
to its appropriate place in tbl2
:
所需的输出是:
Id |tbl1 | tbl2 |
____|_____|______|
1 a a
____|_____|______|
1 b b
____|_____|______|
1 c d
____|_____|______|
2 h c
____|_____|______|
2 j c
____|_____|______|
2 k c
____|_____|______|
...
...
...
...
视觉表现:
我尝试了很多查询...但都没有成功...
i tried many queries... but not succeed...
推荐答案
select T1.id, T1.tbl1, T2.tbl2
from (
select U.id, U.tbl1, U.col
from tbl1
unpivot (tbl1 for col in (c1, c2, c3)) U
) T1
inner join
(
select U.id, U.tbl2, U.Col
from tbl2
unpivot (tbl2 for col in (c1, c2, c3)) U
) T2
on T1.id = T2.id and
T1.col = T2.col
order by T1.id
这篇关于Sql Server 中的单元格比较?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文