|
|
[php]
--只能计算10以内的(不包括10)4个不重复整数之间的不重复组合结果
--如果大于等于10需要考虑如何避免重复
--构造 (a b) (c d)
with tall
as(
select distinct greatest(n1,n2) * least(n2,n1) n12_mu,greatest(n1,n2)||' * '||least(n2,n1) title
from (select a.n n1,
b.n n2
from t24 a,
t24 b)
where n1 != n2
union all
select distinct greatest(n1,n2) - least(n2,n1) n12_mu,greatest(n1,n2)||' - '||least(n2,n1) title
from (select a.n n1,
b.n n2
from t24 a,
t24 b)
where n1 != n2
union all
select distinct greatest(n1,n2) / least(n2,n1) n12_mu,greatest(n1,n2)||' /'||least(n2,n1) title
from (select a.n n1,
b.n n2
from t24 a,
t24 b)
where n1 != n2
and mod(greatest(n1,n2) , least(n2,n1))=0
union all
select distinct greatest(n1,n2) + least(n2,n1) n12_mu,greatest(n1,n2)||' +'||least(n2,n1) title
from (select a.n n1,
b.n n2
from t24 a,
t24 b)
where n1 != n2
),
--构造 ((a b) c)
tall2 as(
select a.n12_mu*b.n n,'('||a.title||')*'||b.n title from tall a, t24 b
where substrb(a.title,1,1)!=n
and substrb(a.title,-1,1)!=n
union all
select a.n12_mu-b.n n,'('||a.title||')-'||b.n title from tall a, t24 b
where substrb(a.title,1,1)!=n
and substrb(a.title,-1,1)!=n
union all
select a.n12_mu/b.n n,'('||a.title||')/'||b.n title from tall a, t24 b
where substrb(a.title,1,1)!=n
and substrb(a.title,-1,1)!=n
union all
select a.n12_mu+b.n n,'('||a.title||')+'||b.n title from tall a, t24 b
where substrb(a.title,1,1)!=n
and substrb(a.title,-1,1)!=n),
--构造 ((a b) (c d))
tall4 as(select a.n12_mu *b.n12_mu n,'('||a.title||')'||'*'||'('||b.title||')' title from tall a, tall b
where replace(replace(replace(replace(a.title,'*',''),'+',''),'-',''),'/','')!=replace(replace(replace(replace(b.title,'*',''),'+',''),'-',''),'/','')
and substrb(a.title,-1,1)!=substrb(b.title,-1,1)
and substrb(a.title,-1,1)!=substrb(b.title,1,1)
and substrb(a.title,1,1)!=substrb(b.title,1,1)
and substrb(a.title,1,1)!=substrb(b.title,-1,1)
union all
select a.n12_mu - b.n12_mu val,'('||a.title||')'||'-'||'('||b.title||')' title from tall a, tall b
where replace(replace(replace(replace(a.title,'*',''),'+',''),'-',''),'/','')!=replace(replace(replace(replace(b.title,'*',''),'+',''),'-',''),'/','')
and substrb(a.title,-1,1)!=substrb(b.title,-1,1)
and substrb(a.title,-1,1)!=substrb(b.title,1,1)
and substrb(a.title,1,1)!=substrb(b.title,1,1)
and substrb(a.title,1,1)!=substrb(b.title,-1,1)
union all
select a.n12_mu / b.n12_mu val,'('||a.title||')'||'/'||'('||b.title||')' title from tall a, tall b
where replace(replace(replace(replace(a.title,'*',''),'+',''),'-',''),'/','')!=replace(replace(replace(replace(b.title,'*',''),'+',''),'-',''),'/','')
and substrb(a.title,-1,1)!=substrb(b.title,-1,1)
and substrb(a.title,-1,1)!=substrb(b.title,1,1)
and substrb(a.title,1,1)!=substrb(b.title,1,1)
and substrb(a.title,1,1)!=substrb(b.title,-1,1)
union all
select a.n12_mu + b.n12_mu val,'('||a.title||')'||'+'||'('||b.title||')' title from tall a, tall b
where replace(replace(replace(replace(a.title,'*',''),'+',''),'-',''),'/','')!=replace(replace(replace(replace(b.title,'*',''),'+',''),'-',''),'/','')
and substrb(a.title,-1,1)!=substrb(b.title,-1,1)
and substrb(a.title,-1,1)!=substrb(b.title,1,1)
and substrb(a.title,1,1)!=substrb(b.title,1,1)
and substrb(a.title,1,1)!=substrb(b.title,-1,1)
),
--构造 (((a b) c) d)
tall3 as(
select a.n*b.n n, '('||a.title||')*'||b.n title
from tall2 a, t24 b
where a.title not like '%'||b.n||'%'
union all
select a.n+b.n n, '('||a.title||')+'||b.n title
from tall2 a, t24 b
where a.title not like '%'||b.n||'%'
union all
select a.n/b.n n, '('||a.title||')/'||b.n title
from tall2 a, t24 b
where a.title not like '%'||b.n||'%'
union all
select a.n-b.n n, '('||a.title||')-'||b.n title
from tall2 a, t24 b
where a.title not like '%'||b.n||'%')
select * from tall3
where n=24
union all
select * from tall4
where n=24;
[/php]
09:59:34 test@REG>select * from t24;
N
----------
1
2
3
4
已用时间: 00: 00: 00.01
09:59:39 test@REG>--只能计算10以内的(不包括10)4个不重复整数之间的不重复组合结果
09:59:44 test@REG>--如果大于等于10需要考虑如何避免重复
09:59:44 test@REG>
09:59:44 test@REG>--构造 (a b) (c d)
09:59:44 test@REG>with tall
09:59:44 2 as(
09:59:44 3 select distinct greatest(n1,n2) * least(n2,n1) n12_mu,greatest(n1,n2)||' * '||least(n2,n1) title
09:59:44 4 from (select a.n n1,
09:59:44 5 b.n n2
09:59:44 6 from t24 a,
09:59:44 7 t24 b)
09:59:44 8 where n1 != n2
09:59:44 9 union all
09:59:44 10 select distinct greatest(n1,n2) - least(n2,n1) n12_mu,greatest(n1,n2)||' - '||least(n2,n1) title
09:59:44 11 from (select a.n n1,
09:59:44 12 b.n n2
09:59:44 13 from t24 a,
09:59:44 14 t24 b)
09:59:44 15 where n1 != n2
09:59:44 16 union all
09:59:44 17 select distinct greatest(n1,n2) / least(n2,n1) n12_mu,greatest(n1,n2)||' /'||least(n2,n1) title
09:59:44 18 from (select a.n n1,
09:59:44 19 b.n n2
09:59:44 20 from t24 a,
09:59:44 21 t24 b)
09:59:44 22 where n1 != n2
09:59:44 23 and mod(greatest(n1,n2) , least(n2,n1))=0
09:59:44 24 union all
09:59:44 25 select distinct greatest(n1,n2) + least(n2,n1) n12_mu,greatest(n1,n2)||' +'||least(n2,n1) title
09:59:44 26 from (select a.n n1,
09:59:44 27 b.n n2
09:59:44 28 from t24 a,
09:59:44 29 t24 b)
09:59:44 30 where n1 != n2
09:59:44 31 ),
09:59:44 32 --构造 ((a b) c)
09:59:44 33 tall2 as(
09:59:44 34 select a.n12_mu*b.n n,'('||a.title||')*'||b.n title from tall a, t24 b
09:59:44 35 where substrb(a.title,1,1)!=n
09:59:44 36 and substrb(a.title,-1,1)!=n
09:59:44 37 union all
09:59:44 38 select a.n12_mu-b.n n,'('||a.title||')-'||b.n title from tall a, t24 b
09:59:44 39 where substrb(a.title,1,1)!=n
09:59:44 40 and substrb(a.title,-1,1)!=n
09:59:44 41 union all
09:59:44 42 select a.n12_mu/b.n n,'('||a.title||')/'||b.n title from tall a, t24 b
09:59:44 43 where substrb(a.title,1,1)!=n
09:59:44 44 and substrb(a.title,-1,1)!=n
09:59:44 45 union all
09:59:44 46 select a.n12_mu+b.n n,'('||a.title||')+'||b.n title from tall a, t24 b
09:59:44 47 where substrb(a.title,1,1)!=n
09:59:44 48 and substrb(a.title,-1,1)!=n),
09:59:44 49 --构造 ((a b) (c d))
09:59:44 50 tall4 as(select a.n12_mu *b.n12_mu n,'('||a.title||')'||'*'||'('||b.title||')' title from tall a, tall b
09:59:44 51 where replace(replace(replace(replace(a.title,'*',''),'+',''),'-',''),'/','')!=replace(replace(replace(replace(b.title,'*',''),'+',''),'-',''),'/','')
09:59:44 52 and substrb(a.title,-1,1)!=substrb(b.title,-1,1)
09:59:44 53 and substrb(a.title,-1,1)!=substrb(b.title,1,1)
09:59:44 54 and substrb(a.title,1,1)!=substrb(b.title,1,1)
09:59:44 55 and substrb(a.title,1,1)!=substrb(b.title,-1,1)
09:59:44 56 union all
09:59:44 57 select a.n12_mu - b.n12_mu val,'('||a.title||')'||'-'||'('||b.title||')' title from tall a, tall b
09:59:44 58 where replace(replace(replace(replace(a.title,'*',''),'+',''),'-',''),'/','')!=replace(replace(replace(replace(b.title,'*',''),'+',''),'-',''),'/','')
09:59:44 59 and substrb(a.title,-1,1)!=substrb(b.title,-1,1)
09:59:44 60 and substrb(a.title,-1,1)!=substrb(b.title,1,1)
09:59:44 61 and substrb(a.title,1,1)!=substrb(b.title,1,1)
09:59:45 62 and substrb(a.title,1,1)!=substrb(b.title,-1,1)
09:59:45 63 union all
09:59:45 64 select a.n12_mu / b.n12_mu val,'('||a.title||')'||'/'||'('||b.title||')' title from tall a, tall b
09:59:45 65 where replace(replace(replace(replace(a.title,'*',''),'+',''),'-',''),'/','')!=replace(replace(replace(replace(b.title,'*',''),'+',''),'-',''),'/','')
09:59:45 66 and substrb(a.title,-1,1)!=substrb(b.title,-1,1)
09:59:45 67 and substrb(a.title,-1,1)!=substrb(b.title,1,1)
09:59:45 68 and substrb(a.title,1,1)!=substrb(b.title,1,1)
09:59:45 69 and substrb(a.title,1,1)!=substrb(b.title,-1,1)
09:59:45 70 union all
09:59:45 71 select a.n12_mu + b.n12_mu val,'('||a.title||')'||'+'||'('||b.title||')' title from tall a, tall b
09:59:45 72 where replace(replace(replace(replace(a.title,'*',''),'+',''),'-',''),'/','')!=replace(replace(replace(replace(b.title,'*',''),'+',''),'-',''),'/','')
09:59:45 73 and substrb(a.title,-1,1)!=substrb(b.title,-1,1)
09:59:45 74 and substrb(a.title,-1,1)!=substrb(b.title,1,1)
09:59:45 75 and substrb(a.title,1,1)!=substrb(b.title,1,1)
09:59:45 76 and substrb(a.title,1,1)!=substrb(b.title,-1,1)
09:59:45 77 ),
09:59:45 78 --构造 (((a b) c) d)
09:59:45 79 tall3 as(
09:59:45 80 select a.n*b.n n, '('||a.title||')*'||b.n title
09:59:45 81 from tall2 a, t24 b
09:59:45 82 where a.title not like '%'||b.n||'%'
09:59:45 83 union all
09:59:45 84 select a.n+b.n n, '('||a.title||')+'||b.n title
09:59:45 85 from tall2 a, t24 b
09:59:45 86 where a.title not like '%'||b.n||'%'
09:59:45 87 union all
09:59:45 88 select a.n/b.n n, '('||a.title||')/'||b.n title
09:59:45 89 from tall2 a, t24 b
09:59:45 90 where a.title not like '%'||b.n||'%'
09:59:45 91 union all
09:59:45 92 select a.n-b.n n, '('||a.title||')-'||b.n title
09:59:45 93 from tall2 a, t24 b
09:59:45 94 where a.title not like '%'||b.n||'%')
09:59:45 95 select * from tall3
09:59:45 96 where n=24
09:59:45 97 union all
09:59:45 98 select * from tall4
09:59:45 99 where n=24;
N TITLE
---------- -------------------------
24 ((3 * 2)*4)*1
24 ((4 * 2)*3)*1
24 ((4 * 3)*2)*1
24 ((3 * 1)*4)*2
24 ((4 * 1)*3)*2
24 ((4 * 3)*1)*2
24 ((3 /1)*4)*2
24 ((4 /1)*3)*2
24 ((4 * 3)/1)*2
24 ((2 * 1)*4)*3
24 ((4 * 1)*2)*3
24 ((4 * 2)*1)*3
24 ((2 /1)*4)*3
24 ((4 /1)*2)*3
24 ((4 * 2)/1)*3
24 ((2 * 1)*3)*4
24 ((3 * 1)*2)*4
24 ((3 * 2)*1)*4
24 ((2 /1)*3)*4
24 ((3 /1)*2)*4
24 ((3 * 2)/1)*4
24 ((2 +1)+3)*4
24 ((3 +1)+2)*4
24 ((3 +2)+1)*4
24 ((3 * 2)*4)/1
24 ((4 * 2)*3)/1
24 ((4 * 3)*2)/1
24 (4 * 3)*(2 * 1)
24 (4 * 2)*(3 * 1)
24 (3 * 2)*(4 * 1)
24 (4 * 1)*(3 * 2)
24 (4 /1)*(3 * 2)
24 (3 * 1)*(4 * 2)
24 (3 /1)*(4 * 2)
24 (2 * 1)*(4 * 3)
24 (2 /1)*(4 * 3)
24 (4 * 3)*(2 /1)
24 (4 * 2)*(3 /1)
24 (3 * 2)*(4 /1)
24 (4 +2)*(3 +1)
24 (3 +1)*(4 +2)
已选择41行。
已用时间: 00: 00: 00.10
09:59:54 test@REG>truncate table t24;
表被截断。
已用时间: 00: 00: 00.06
10:00:00 test@REG>insert into t24 values (3);
已创建 1 行。
已用时间: 00: 00: 00.03
10:00:15 test@REG>insert into t24 values (5);
已创建 1 行。
已用时间: 00: 00: 00.01
10:00:20 test@REG>insert into t24 values (6);
已创建 1 行。
已用时间: 00: 00: 00.00
10:00:23 test@REG>insert into t24 values (9);
已创建 1 行。
已用时间: 00: 00: 00.01
10:00:26 test@REG>commit;
提交完成。
已用时间: 00: 00: 00.01
10:00:28 test@REG>--只能计算10以内的(不包括10)4个不重复整数之间的不重复组合结果
10:00:57 test@REG>--如果大于等于10需要考虑如何避免重复
10:00:57 test@REG>
10:00:57 test@REG>--构造 (a b) (c d)
10:00:57 test@REG>with tall
10:00:57 2 as(
10:00:57 3 select distinct greatest(n1,n2) * least(n2,n1) n12_mu,greatest(n1,n2)||' * '||least(n2,n1) title
10:00:57 4 from (select a.n n1,
10:00:57 5 b.n n2
10:00:57 6 from t24 a,
10:00:57 7 t24 b)
10:00:57 8 where n1 != n2
10:00:57 9 union all
10:00:57 10 select distinct greatest(n1,n2) - least(n2,n1) n12_mu,greatest(n1,n2)||' - '||least(n2,n1) title
10:00:57 11 from (select a.n n1,
10:00:57 12 b.n n2
10:00:57 13 from t24 a,
10:00:57 14 t24 b)
10:00:57 15 where n1 != n2
10:00:57 16 union all
10:00:57 17 select distinct greatest(n1,n2) / least(n2,n1) n12_mu,greatest(n1,n2)||' /'||least(n2,n1) title
10:00:57 18 from (select a.n n1,
10:00:57 19 b.n n2
10:00:57 20 from t24 a,
10:00:57 21 t24 b)
10:00:57 22 where n1 != n2
10:00:57 23 and mod(greatest(n1,n2) , least(n2,n1))=0
10:00:57 24 union all
10:00:57 25 select distinct greatest(n1,n2) + least(n2,n1) n12_mu,greatest(n1,n2)||' +'||least(n2,n1) title
10:00:57 26 from (select a.n n1,
10:00:57 27 b.n n2
10:00:57 28 from t24 a,
10:00:57 29 t24 b)
10:00:57 30 where n1 != n2
10:00:57 31 ),
10:00:57 32 --构造 ((a b) c)
10:00:57 33 tall2 as(
10:00:57 34 select a.n12_mu*b.n n,'('||a.title||')*'||b.n title from tall a, t24 b
10:00:57 35 where substrb(a.title,1,1)!=n
10:00:57 36 and substrb(a.title,-1,1)!=n
10:00:57 37 union all
10:00:57 38 select a.n12_mu-b.n n,'('||a.title||')-'||b.n title from tall a, t24 b
10:00:57 39 where substrb(a.title,1,1)!=n
10:00:57 40 and substrb(a.title,-1,1)!=n
10:00:57 41 union all
10:00:57 42 select a.n12_mu/b.n n,'('||a.title||')/'||b.n title from tall a, t24 b
10:00:57 43 where substrb(a.title,1,1)!=n
10:00:57 44 and substrb(a.title,-1,1)!=n
10:00:57 45 union all
10:00:57 46 select a.n12_mu+b.n n,'('||a.title||')+'||b.n title from tall a, t24 b
10:00:57 47 where substrb(a.title,1,1)!=n
10:00:57 48 and substrb(a.title,-1,1)!=n),
10:00:57 49 --构造 ((a b) (c d))
10:00:57 50 tall4 as(select a.n12_mu *b.n12_mu n,'('||a.title||')'||'*'||'('||b.title||')' title from tall a, tall b
10:00:57 51 where replace(replace(replace(replace(a.title,'*',''),'+',''),'-',''),'/','')!=replace(replace(replace(replace(b.title,'*',''),'+',''),'-',''),'/','')
10:00:57 52 and substrb(a.title,-1,1)!=substrb(b.title,-1,1)
10:00:57 53 and substrb(a.title,-1,1)!=substrb(b.title,1,1)
10:00:57 54 and substrb(a.title,1,1)!=substrb(b.title,1,1)
10:00:57 55 and substrb(a.title,1,1)!=substrb(b.title,-1,1)
10:00:57 56 union all
10:00:57 57 select a.n12_mu - b.n12_mu val,'('||a.title||')'||'-'||'('||b.title||')' title from tall a, tall b
10:00:57 58 where replace(replace(replace(replace(a.title,'*',''),'+',''),'-',''),'/','')!=replace(replace(replace(replace(b.title,'*',''),'+',''),'-',''),'/','')
10:00:57 59 and substrb(a.title,-1,1)!=substrb(b.title,-1,1)
10:00:57 60 and substrb(a.title,-1,1)!=substrb(b.title,1,1)
10:00:57 61 and substrb(a.title,1,1)!=substrb(b.title,1,1)
10:00:57 62 and substrb(a.title,1,1)!=substrb(b.title,-1,1)
10:00:57 63 union all
10:00:57 64 select a.n12_mu / b.n12_mu val,'('||a.title||')'||'/'||'('||b.title||')' title from tall a, tall b
10:00:57 65 where replace(replace(replace(replace(a.title,'*',''),'+',''),'-',''),'/','')!=replace(replace(replace(replace(b.title,'*',''),'+',''),'-',''),'/','')
10:00:57 66 and substrb(a.title,-1,1)!=substrb(b.title,-1,1)
10:00:57 67 and substrb(a.title,-1,1)!=substrb(b.title,1,1)
10:00:57 68 and substrb(a.title,1,1)!=substrb(b.title,1,1)
10:00:57 69 and substrb(a.title,1,1)!=substrb(b.title,-1,1)
10:00:57 70 union all
10:00:57 71 select a.n12_mu + b.n12_mu val,'('||a.title||')'||'+'||'('||b.title||')' title from tall a, tall b
10:00:57 72 where replace(replace(replace(replace(a.title,'*',''),'+',''),'-',''),'/','')!=replace(replace(replace(replace(b.title,'*',''),'+',''),'-',''),'/','')
10:00:57 73 and substrb(a.title,-1,1)!=substrb(b.title,-1,1)
10:00:57 74 and substrb(a.title,-1,1)!=substrb(b.title,1,1)
10:00:57 75 and substrb(a.title,1,1)!=substrb(b.title,1,1)
10:00:57 76 and substrb(a.title,1,1)!=substrb(b.title,-1,1)
10:00:57 77 ),
10:00:57 78 --构造 (((a b) c) d)
10:00:57 79 tall3 as(
10:00:57 80 select a.n*b.n n, '('||a.title||')*'||b.n title
10:00:57 81 from tall2 a, t24 b
10:00:57 82 where a.title not like '%'||b.n||'%'
10:00:57 83 union all
10:00:57 84 select a.n+b.n n, '('||a.title||')+'||b.n title
10:00:57 85 from tall2 a, t24 b
10:00:57 86 where a.title not like '%'||b.n||'%'
10:00:57 87 union all
10:00:57 88 select a.n/b.n n, '('||a.title||')/'||b.n title
10:00:57 89 from tall2 a, t24 b
10:00:57 90 where a.title not like '%'||b.n||'%'
10:00:57 91 union all
10:00:57 92 select a.n-b.n n, '('||a.title||')-'||b.n title
10:00:57 93 from tall2 a, t24 b
10:00:57 94 where a.title not like '%'||b.n||'%')
10:00:57 95 select * from tall3
10:00:57 96 where n=24
10:00:57 97 union all
10:00:57 98 select * from tall4
10:00:57 99 where n=24;
N TITLE
---------- -------------------------
24 ((9 +5)-6)*3
24 ((9 - 6)+5)*3
24 ((6 * 5)-9)+3
24 ((5 - 3)*9)+6
24 ((6 - 3)*5)+9
24 ((9 - 3)*5)-6
24 ((6 +5)*3)-9
24 ((6 * 5)+3)-9
24 (5 +3)*(9 - 6)
24 (9 - 6)*(5 +3)
24 (6 * 5)-(9 - 3)
已选择11行。
已用时间: 00: 00: 00.12
10:00:59 test@REG>spool off
|
|