加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

sql独特的记录拼图

发布时间:2020-12-12 06:58:44 所属栏目:MsSql教程 来源:网络整理
导读:难题是选择独特的对.以下示例中的语法适用于Mssql declare @t table (a int,b int)insert into @t (a,b) values (1,2)insert into @t (a,b) values (2,1)insert into @t (a,3)insert into @t (a,b) values (3,b) values (5,6)select * from @t -- it outputs
难题是选择独特的对.以下示例中的语法适用于Mssql
declare @t table (a int,b int)

insert into @t (a,b) values (1,2)
insert into @t (a,b) values (2,1)
insert into @t (a,3)
insert into @t (a,b) values (3,b) values (5,6)


select * from @t -- it outputs 5 records.

我需要获得唯一的对,而不管顺序a,b,这应该给我三条记录

输出应该是

(1,2),(1,3),(5,6)

我没有想法,会很感激帮助:)

解决方法

select      distinct 

            case when a<b then a else b end,case when a<b then b else a end 

from        @t
;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读