I am not able to find the solution for my problem. I have 4 tables:
BomModule: This table represents a module in the database.
CREATE TABLE "BOMMODULE"
(
"MODULEID" NUMBER(10,0) NOT NULL ENABLE,
"ISROOTMODULE" NUMBER(1,0) NOT NULL ENABLE,
"MODULENAME" VARCHAR2(255 CHAR),
...
)
BomItem: This table represents a leaf – or an item in the database.
CREATE TABLE "BOMITEM"
(
"ITEMID" NUMBER(10,0) NOT NULL ENABLE,
...
)
ModuleConnection: This table maps a module to another parent module. You can define the quantity of submodules that belong to a specific parent module.
CREATE TABLE "MODULECONNECTION"
(
"ID" NUMBER(10,0) NOT NULL ENABLE,
"QUANTITY" NUMBER(10,0) NOT NULL ENABLE,
"SUBMODULE_MODULEID" NUMBER(10,0) NOT NULL ENABLE,
"PARENTMODULE_MODULEID" NUMBER(10,0) NOT NULL ENABLE,
...
)
ItemModuleConnection:
This table maps all leave-items to a module. Furthermore, you can define the quantity of items for one module.
CREATE TABLE "ITEMMODULECONNECTION"
(
"ID" NUMBER(10,0) NOT NULL ENABLE,
"QUANTITY" NUMBER(10,0) NOT NULL ENABLE,
"ITEMID" NUMBER(10,0),
"MODULEID" NUMBER(10,0),
...
)
As you can see from the table structure, items and modules are connected to each other and have different quantities. Due to the fact that those connections are very flexible, I am not able to create a SQL statement, that will provide me the total quantity for an item:
select quantity from ...... where itemId = xy;
The SQL statement should check all quantities from the item to the root module and multiply them:
2 x rootmodule (total 2)
-- 1x submodule 1 (total 2)
-- 2x submodule 2 (total 4)
---- 5x item 1 (total 20)
---- 6x item 2 (total 24)
Please help me create this sql statement, much appreciate your answer!
Constraints:
– It has to be a SQL statement (It is used in a Java application)
– Database is Oracle 11g
I was able to solve this problem by using Java, instead of SQL. This is my approach:
Before I print the single Items, I call this updateBom()-function and then retrieve the values from the HashMap: