首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Mysql >

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

2012-09-11 
求一mysql函数 返回一个号码的所有组合如题:例如传入1234 则返回24种组合 即:1234,1243,2134,2341……传入11

求一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

热点排行