3
Good morning!
there is some way to create a query that brings the "product" and all the "Components and Subcomponents" of the structure of this product?
Let me try to explain better
Structure
Imagery
Image Link: https://i.stack.Imgur.com/tGNZ4.jpg
Text format
- Bicicleta
|
+ - Guidão
|
+ - Quadro
| |
| + - Garfo
|
+ - Banco
| |
| + - Selim
|
+ - Roda
|
+ - Aro
|
+ - Raio
|
+ - Pneu
|
+ - Camara
I have the "bike" equipment structure inserted in the database and I need to get who is the "product" and all that are below (Components[eCOMP] and Subcomponents[eCOMP]) connecting all to the main product
Example
+--------+----------+--------+----------+
|eCOD |eDESC2 |eCOMP | eDESC2 |
+--------+----------+--------+----------+
|01.0001 |Bicicleta |01.0002 | Guidão |
|01.0001 |Bicicleta |01.0003 | Quadro |
|01.0001 |Bicicleta |01.0004 | Garfo |
|01.0001 |Bicicleta |01.0005 | Banco |
|01.0001 |Bicicleta |01.0006 | Selim |
|01.0001 |Bicicleta |01.0007 | Roda |
|01.0001 |Bicicleta |01.0008 | Aro |
|01.0001 |Bicicleta |01.0009 | Raio |
|01.0001 |Bicicleta |01.0010 | Pneu |
|01.0001 |Bicicleta |01.0011 | Camara |
+--------+----------+--------+----------+
Table structure
Data in Sqlfiddle
Data in Text format
Cadastro de Produto [Tabela PROD]
pCOD pDESC
01.0001 Bicicleta
01.0002 Guidão
01.0003 Quadro
01.0004 Garfo
01.0005 Banco
01.0006 Selim
01.0007 Roda
01.0008 Aro
01.0009 Raio
01.0010 Pneu
01.0011 Camara
Estrutura do Produto [Tabela ESTR]
eCOD eCOMP eQTD eNiv
01.0001 01.0002 1 1
01.0001 01.0003 1 1
01.0003 01.0004 1 2
01.0001 01.0005 1 1
01.0005 01.0006 1 2
01.0001 01.0007 2 1
01.0007 01.0008 1 2
01.0008 01.0009 1 3
01.0008 01.0010 1 3
01.0010 01.0011 1 4
Data in SQL Format
CREATE TABLE PROD (
pCOD varchar(15),
pDESC varchar(100)
);
insert into PROD (pCOD, pDESC) values
('01.0001','Bicicleta'),
('01.0002','Guidão'),
('01.0003','Quadro'),
('01.0004','Garfo'),
('01.0005','Banco'),
('01.0006','Selim'),
('01.0007','Roda'),
('01.0008','Aro'),
('01.0009','Raio'),
('01.0010','Pneu'),
('01.0011','Camara')
CREATE TABLE ESTR (
eCOD varchar(15),
eCOMP varchar(15),
eQTD integer,
eNIV integer
);
insert into ESTR (eCOD, eCOMP, eQTD, eNIV) values
('01.0001','01.0002','1','1'),
('01.0001','01.0003','1','1'),
('01.0003','01.0004','1','2'),
('01.0001','01.0005','1','1'),
('01.0005','01.0006','1','2'),
('01.0001','01.0007','2','1'),
('01.0007','01.0008','1','2'),
('01.0008','01.0009','1','3'),
('01.0008','01.0010','1','3'),
('01.0010','01.0011','1','4')
Put the structure of tables?
– Lucas Brogni
Include the image in the question, besides getting better to view, some links are blocked depending on where we access the site
– Ricardo Pontual
I will add the table structure in text format.
– Roberto Valentim