SELECT a.f1+','+b.f1
from (
select 'A' as f1
union all select 'B'
union all select 'C'
union all select 'D'
) a
,
(select 'A' as f1
union all select 'B'
union all select 'C'
union all select 'D'
) b
where a.f1 < b.f1
order by a.f1
----
A,B
A,C
A,D
B,C
B,D
C,D(所影响的行数为 6 行)
from (
select 'A' as f1
union all select 'B'
union all select 'C'
union all select 'D'
) a
,
(select 'A' as f1
union all select 'B'
union all select 'C'
union all select 'D'
) b
where a.f1 < b.f1
order by a.f1
----
A,B
A,C
A,D
B,C
B,D
C,D(所影响的行数为 6 行)
from(
select a='A'
union all select 'B'
union all select 'C'
union all select 'D'
) a,(
select b='A'
union all select 'B'
union all select 'C'
union all select 'D'
) b
from(
select a='A'
union all select 'B'
union all select 'C'
union all select 'D'
) a,(
select b='A'
union all select 'B'
union all select 'C'
union all select 'D'
) b
from(
select a='A'
union all select 'B'
union all select 'C'
union all select 'D'
) a,(
select b='A'
union all select 'B'
union all select 'C'
union all select 'D'
) b
where a<b
order by a1/*--测试结果
a1 a2
---- ----
AB A,B
AC A,C
AD A,D
BC B,C
BD B,D
CD C,D(所影响的行数为 6 行)
--*/
select isnull(a.le+b.le,' ') from #tb a full join #tb b on a.字段名<b.字段名
SELECT a.f1+','+b.f1+','+c.f1
from
(
select 'A' as f1
union all select 'B'
union all select 'C'
union all select 'D'
) a
,
(select 'A' as f1
union all select 'B'
union all select 'C'
union all select 'D'
) b
,
(select 'A' as f1
union all select 'B'
union all select 'C'
union all select 'D'
) c
where a.f1 < b.f1 and b.f1<c.f1
order by a.f1