Sql Server查询结果并排 [英] Sql Server Query Result Side by Side
本文介绍了Sql Server查询结果并排的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一张桌子,有这样的数据..
Id地址名称
1街约翰
2街B金
我 想要 到 display result 喜欢
Id_1 Address_1 < span class =code-leadattribute> val_1 Id_2 Address_2 Val_2
1 Street A 跨度> John 2 Street_B Kim
我尝试过连接和枢轴但没有结果..
请帮帮我..
提前致谢。
解决方案
你可以用表格的笛卡尔积与它自己做,然后过滤出记录,其中ID1 = ID2
select * from Table T1 cross join Table T2其中t1.Id<> t2.Id
Hi i have a table, having data like this..
Id Address Name
1 Street A John
2 Street B kim
I want to display the result like
Id_1 Address_1 val_1 Id_2 Address_2 Val_2
1 Street A John 2 Street_B Kim
I have tried with joins and pivot but no result..
Please help me..
Thanks in advance.
解决方案
You could do it with a Cartesian product of the table with itself, then filter out records where ID1 = ID2
select * from Table T1 cross join Table T2 where t1.Id <> t2.Id
这篇关于Sql Server查询结果并排的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文