如题:例如传入1234 则返回24种组合 即:1234,1243,2134,2341……
传入1123返回12种:1123,1132,3121……
传入1122 返回6种: 1122,1212,1221,2211,2121,2112
传入1112 返回4种: 1112,1121,1211,2111

解决方案 »

  1.   

    这种不就是简单的数学上的排列吗,算法都有了,用sql写出来,很简单的
      

  2.   

    把每个数字挨个插入一个表中tmp然后select distinct concat(A.num,B.num,C.num,D.num)
    from temp A,temp B,temp C ,temp D
      

  3.   

    select distinct concat(mid('例如传入',t1.x,1) ,mid('例如传入',t2.x,1) ,mid('例如传入',t3.x,1) ,mid('例如传入',t4.x,1) )
    from (
    select 1 as x union all
    select 2 union all
    select 3 union all
    select 4 
    ) t1,
    (
    select 1 as x union all
    select 2 union all
    select 3 union all
    select 4 
    ) t3,
    (
    select 1 as x union all
    select 2 union all
    select 3 union all
    select 4 
    ) t3,
    (
    select 1 as x union all
    select 2 union all
    select 3 union all
    select 4 
    ) t4