SQL> select o.p as "排列" from
   2  (select replace (sys_connect_by_path( value, ',' ) , ',' ) p
   3  from users connect by nocycle value != prior value) o
   4  where length(o.p) =3;各位大侠帮帮忙

解决方案 »

  1.   

    sys_connect_by_path 是oracle层次查询的函数。专门处理树形结构的
    sqlserver 在2008中加入层次查询函数。
      

  2.   

    SQL> create table users (name char(2),value char(1),id number); Table created SQL> insert into users values('甲','a',1); 1 row inserted SQL> insert into users values('乙','b',2); 1 row inserted SQL> insert into users values('丙','c',3); 1 row inserted SQL> insert into users values('丁','d',4); 1 row inserted SQL> commit; Commit complete SQL> select * from users; NAME VALUE         ID
     ---- ----- ----------
     甲   a              1
     乙   b              2
     丙   c              3
     丁   d              4SQL> select o.p as "排列" from
       2  (select replace (sys_connect_by_path( value, ',' ) , ',' ) p
       3  from users connect by nocycle value != prior value) o
       4  where length(o.p) =2; 排列
     --------------------------------------------------------------------------------
     ab
     ac
     ad
     ba
     bc
     bd
     ca
     cb
     cd
     da
     db
     dc 12 rows selected
     
    SQL> select o.p as "排列" from
       2  (select replace (sys_connect_by_path( value, ',' ) , ',' ) p
       3  from users connect by nocycle value != prior value) o
       4  where length(o.p) =3; 排列
     --------------------------------------------------------------------------------
     abc
     abd
     acb
     acd
     adb
     adc
     bac
     bad
     bca
     bcd
     bda
     bdc
     cab
     cad
     cba
     cbd
     cda
     cdb
     dab
     dac 排列
     --------------------------------------------------------------------------------
     dba
     dbc
     dca
     dcb 24 rows selected 我就是想用sqlserver也得到这种效果