Hi,
I have 3 tables:
- two with hierarchical structures
(like "dimensions" of recursive type of hierarchy);
- one with summing data (like "facts" with X column).
There are here:
1) DIM1 (ID1, PARENT2, NAME1)
2) DIM2 (ID2, PARENT2, NAME2)
3) FACTS (ID1, ID2, X)
Example of DIM1 table:
-- 1 0 DIM1
---- 2 1 DIM1-A
------ 3 2 DIM1-A-A
-------- 4 3 DIM1-A-A-A
-------- 5 3 DIM1-A-A-B
------ 6 2 DIM1-A-B
-------- 7 6 DIM1-A-B-A
-------- 8 6 DIM1-A-B-B
------ 9 2 DIM1-A-C
---- 10 1 DIM1-B
------ 11 10 DIM1-B-C
------ 12 10 DIM1-B-D
---- 13 1 DIM1-C
Example of DIM2 table:
-- 1 0 DIM2
---- 2 1 DIM2-A
------ 3 2 DIM2-A-A
-------- 4 3 DIM2-A-A-A
-------- 5 3 DIM2-A-A-B
-------- 6 3 DIM2-A-B-C
------ 7 2 DIM2-A-B
---- 8 1 DIM2-B
---- 9 1 DIM2-C
Example of FACTS table:
1 1 100
1 2 30
1 3 500
-- ................
13 9 200
And I would like to create the only SELECT
where I will specify parent for DIM1 (for example ID1=2 for DIM1-A)
and parent for DIM2 (for example ID2=2 for DIM2-A) and
SELECT will generate report like this:
Name_of_1 Name_of_2 Sum_of_X
--------- --------- ----------
DIM1-A-A DIM2-A-A (some sum)
DIM1-A-A DIM2-A-B (some sum)
DIM1-A-B DIM2-A-A (some sum)
DIM1-A-B DIM2-A-B (some sum)
DIM1-A-C DIM2-A-A (some sum)
DIM1-A-C DIM2-A-B (some sum)
I would like to use CONNECT BY phrase, START WITH phrase,
SUM phrase, GROUP BY phrase and OUTER or INNER (?) JOIN.
And nothing more extensions of Oracle 10.2.
In other words: only with "classic" SQL and
only Oracle extensions for hierarchy queries.
Is it possible?
I tried some experiments with question in
http://stackoverflow.com/questions/2922167/mixing-together-connect-by-inner-join-and-sum-with-oracle
(where is a very nice solution but only for one
dimension table ("Tasks"), but I need to JOIN two dimension tables
to one facts table), but I was not succesful.
Thank you very much in advance.
Mirek