求一mysql函数 返回一个号码的所有组合解决方法

求一mysql函数 返回一个号码的所有组合

如题:例如传入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



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




把每个数字挨个插入一个表中tmp

然后

select distinct concat(A.num,B.num,C.num,D.num)

from temp A,temp B,temp C ,temp D




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

求一mysql函数 返回一个号码的所有组合解决方法

相关文章:

你感兴趣的文章:

标签云: