경우의수를 구하는 부분에서 데이터베이스 쿼리문으로 가능한가 싶어 조인과 유니온을 조합하여
하여 보았지만.. 도통 제가 원하는 결과가 나오지가 않는군요..
Test A 테이블에는
t1 t2 t3
1 2 3
1 2 6
1 2 7
Test B 테이블에는
t1 t2 t3
10 11 14
10 11 15
10 11 16
일때 t1 과 t2 와 t3 의 모든 경우의수를 구하는 겁니다.
결과)
Test C
t1 t2 t3
1 2 3
1 2 6
1 2 7
1 2 14
1 2 15
1 2 16
1 11 14
1 11 15
1 11 16
10 11 14
....
위 와 같은 형식으로 t1은 t2 보다 작아야 하고, t2는 t3 보다 작아야 합니다.
쿼리문으로 가능 한가요?? 도와주세요..
조합규칙에 따라 달라질수는 있는데....
with
crossT1
as (
select 1 idx union all
select 2 idx union all
select 3 idx
) ,
crossT2
as (
select 1 idx union all
select 2 idx
) ,
TestA
as (
select 1 t1 , 2 t2 , 3 t3 union all
select 1 , 2 , 6 union all
select 1 , 2 , 7 ) ,
TestB
as (
select 10 t1 ,11 t2, 14 t3 union all
select 10 ,11 , 15 union all
select 10 ,11 , 16 ) ,
resulT
as (
select distinct 'TestA' tgb,*
from TestA
unpivot
( value FOR T_gb in ( t1,t2,t3)
) as unpvt
union all
select distinct 'TestB' tgb,*
from TestB
unpivot
( value FOR T_gb in ( t1,t2,t3)
) as unpvt
)
select a.value
, b.value
, c.value
from (select * from resulT where T_gb = 't1') a
, (select * from resulT where T_gb = 't2') b
, (select * from resulT where T_gb = 't3') c
where a.value < b.value and b.value < c.value
order by a.value
, b.value
, c.value