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 行)

解决方案 »

  1.   

    select a+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
      

  2.   

    --如果要中间的','select a+','+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
      

  3.   

    --上面的包含了所有可能的组合,如果只是楼主要求的组合,就用:select a1=a+b,a2=a+','+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 行)
    --*/
      

  4.   

    select id=identity(int ,1,1) ,* into #tb  from table 
    select isnull(a.le+b.le,' ') from #tb a full join #tb b on a.字段名<b.字段名
      

  5.   

    select a.le+b.le from test5 a,test5 b where a.le<b.le
      

  6.   

    ---三种组合!
    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