0
The 1st select shows the following fields:
CONCAT - FILIAL - COD. PRODUTO - DESCRICAO - QNTD. VENDAS PUB.
11 - 1 - 1 - PRODUTO 1 - 10
12 - 1 - 2 - PRODUTO 2 - 20
13 - 1 - 3 - PRODUTO 3 - 30
2nd select shows the following fields:
CONCAT - FILIAL - COD. PRODUTO - DESCRICAO - QNTD. VENDAS PRIV.
11 - 1 - 1 - PRODUTO 1 - 11
12 - 1 - 2 - PRODUTO 2 - 22
13 - 1 - 3 - PRODUTO 3 - 33
19 - 1 - 9 - PRODUTO 9 - 99
I need to join these 2 selects where I can display the result as follows:
CONCAT - FILIAL - COD. PRODUTO - DESCRICAO - QNTD. VENDAS PUB. - QNTD. VENDAS PRIV.
11 - 1 - 1 - PRODUTO 1 - 10 - 11
12 - 1 - 2 - PRODUTO 2 - 20 - 22
13 - 1 - 3 - PRODUTO 3 - 30 - 33
19 - 1 - 9 - PRODUTO 9 - 0 - 99
Using Union does not answer me, because the sums of the field QNTD. PRIV SALES. would be in the same field of publ.
SELECT
CONCAT(PCPEDC.CODFILIAL, PCPEDI.CODPROD) AS CONCAT,
PCPEDC.CODFILIAL AS FILIAL,
PCPEDI.CODPROD AS "COD. PRODUTO",
PCPRODUT.DESCRICAO AS DESCRICAO,
Sum(PCPEDI.QT) AS "QNTD. VENDAS PUB."
FROM
PCPEDI,
PCCLIENT,
PCPEDC,
PCATIVI,
PCPRODUT
WHERE
PCPEDI.CODPROD = PCPRODUT.CODPROD
AND PCPEDI.CODCLI = PCCLIENT.CODCLI
AND PCPEDI.NUMPED = PCPEDC.NUMPED
AND PCCLIENT.CODATV1 = PCATIVI.CODATIV
AND PCPEDI.POSICAO = 'F'
AND PCCLIENT.CODATV1 IN (60, 52, 51, 43, 44, 49)
AND PCPEDC.CODFILIAL IN (1)
AND PCPEDC.CONDVENDA = 1
GROUP BY
PCPEDI.CODPROD,
PCPEDC.CODFILIAL
ORDER BY
"COD. PRODUTO"
SELECT
CONCAT(PCPEDC.CODFILIAL, PCPEDI.CODPROD) AS CONCAT,
PCPEDC.CODFILIAL AS FILIAL,
PCPEDI.CODPROD AS "COD. PRODUTO",
PCPRODUT.DESCRICAO AS DESCRICAO,
Sum(PCPEDI.QT) AS "QNTD. VENDAS PRIV."
FROM
PCPEDI,
PCCLIENT,
PCPEDC,
PCATIVI,
PCPRODUT
WHERE
PCPEDI.CODPROD = PCPRODUT.CODPROD
AND PCPEDI.CODCLI = PCCLIENT.CODCLI
AND PCPEDI.NUMPED = PCPEDC.NUMPED
AND PCCLIENT.CODATV1 = PCATIVI.CODATIV
AND PCPEDI.POSICAO = 'F'
AND PCCLIENT.CODATV1 NOT IN (60, 52, 51, 43, 44, 49, 62, 64, 2, 99, 1)
AND PCPEDC.CODFILIAL IN (1)
AND PCPEDC.CONDVENDA = 1
GROUP BY
PCPEDI.CODPROD,
PCPEDC.CODFILIAL
ORDER BY
"COD. PRODUTO"
Developer Pre Solution:
SELECT VENDAS_PUBLICAS.CONCAT,
--demais colunas
VENDAS_PUBLICAS.QNTD_VENDAS_PUB,
VENDAS_PRIVADAS.QNTD_VENDAS_PRIV
FROM
(SELECT
CONCAT(PCPEDC.CODFILIAL, PCPEDI.CODPROD) AS CONCAT,
PCPEDC.CODFILIAL AS FILIAL,
PCPEDI.CODPROD AS "COD. PRODUTO",
PCPRODUT.DESCRICAO AS DESCRICAO,
Sum(PCPEDI.QT) AS "QNTD_VENDAS_PUB"
FROM PCPEDI, PCCLIENT, PCPEDC, PCATIVI, PCPRODUT
WHERE PCPEDI.CODPROD = PCPRODUT.CODPROD
AND PCPEDI.CODCLI = PCCLIENT.CODCLI
AND PCPEDI.NUMPED = PCPEDC.NUMPED
AND PCCLIENT.CODATV1 = PCATIVI.CODATIV
AND PCPEDI.POSICAO = 'F'
AND PCCLIENT.CODATV1 IN (60, 52, 51, 43, 44, 49)
AND PCPEDC.CODFILIAL IN (1)
AND PCPEDC.CONDVENDA = 1
GROUP BY PCPEDI.CODPROD, PCPEDC.CODFILIAL
ORDER BY "COD. PRODUTO") as VENDAS_PUBLICAS,
(SELECT CONCAT(PCPEDC.CODFILIAL, PCPEDI.CODPROD) AS CONCAT,
PCPEDC.CODFILIAL AS FILIAL,
PCPEDI.CODPROD AS "COD. PRODUTO",
PCPRODUT.DESCRICAO AS DESCRICAO,
Sum(PCPEDI.QT) AS "QNTD_VENDAS_PRIV"
FROM PCPEDI, PCCLIENT, PCPEDC, PCATIVI, PCPRODUT
WHERE PCPEDI.CODPROD = PCPRODUT.CODPROD
AND PCPEDI.CODCLI = PCCLIENT.CODCLI
AND PCPEDI.NUMPED = PCPEDC.NUMPED
AND PCCLIENT.CODATV1 = PCATIVI.CODATIV
AND PCPEDI.POSICAO = 'F'
AND PCCLIENT.CODATV1 NOT IN (60, 52, 51, 43, 44, 49, 62, 64, 2, 99, 1)
AND PCPEDC.CODFILIAL IN (1)
AND PCPEDC.CONDVENDA = 1
GROUP BY PCPEDI.CODPROD, PCPEDC.CODFILIAL
ORDER BY "COD. PRODUTO") as VENDAS_PRIVADAS
WHERE VENDAS_PUBLICAS.CONCAT = VENDAS_PRIVADAS.CONCAT
What do you really want with it? Have you tried using the
union
or theunion all
?– Marconi
I already tried yes. Only the 2 sums are in the same column. What I need is 2 columns of the sums
– Adalberto
Your question is a little confused tries to improve she will certainly appear many people to help.
– Marconi
Marconi, I edited the description with examples. See if you can help me or someone else.
– Adalberto
Can someone help me?
– Adalberto
If you create the QTDE SALES PUB and QTOF PRIV SALES fields for the two selects can’t help? A column will be empty in one of the two select’s
– adelmo00
Um, got it. I’ll try here and return.
– Adalberto
@Adalberto worked out well?
– adelmo00