22,209
社区成员
发帖
与我相关
我的任务
分享
declare @T table (a1 int,b1 int)
insert into @T
select 1,1 union all
select 2,2 union all
select 3,3
select a.a1,b.b1 from @T a cross join @T b where a.a1<b.a1
/*
a1 b1
----------- -----------
1 2
1 3
2 3
*/
--字符也是一样的呀?
select * from
(select '1' a1 union select '2' a1 union select '3' a1) a,
(select '1' b1 union select '2' b1 union select '3' b1) b
where a.a1<b.b1
/*
a1 b1
---- ----
1 2
1 3
2 3
*/