SQL grouping

Asked

Viewed 52 times

0

I need to select the following:

'SELECT TR.CODPARC, TR.NOMEPARC, TB.CODVEND, TV.APELIDO, TV.AD_CARTAOCAMP, TP.AD_CAMPLENTE, TP.AD_CAMPPONTOS
FROM TGFCAB TB, TGFITE TE, TGFPRO TP, TGFPAR TR, TGFVEN TV
Where Tb.Nunota = Te.Nunota 
AND TB.CODVEND = TV.CODVEND
AND TP.CODPROD = TE.CODPROD
AND TB.CODPARC = TR.CODPARC
And Tb.Tipmov = 'P'
AND TB.CODTIPOPER IN (3100, 3102, 3105)
AND TB.DTNEG >= :PERIODO.INI
AND TB.DTNEG <= :PERIODO.FIN
AND TV.AD_CARTAOCAMP IS NOT NULL
ORDER BY TB.KLKCLBOSE'

Bringing a line only with the result of

'SELECT TR.CODPARC, TR.NOMEPARC, TB.CODVEND, TV.APELIDO, TV.AD_CARTAOCAMP' 

That will be exactly equal and the sum of the fields TP.AD_CAMPLENTE, TP.AD_CAMPPONTOS on the same line.

  • To help you faster, put an example of data entry http:/sqlfiddle.com/ and the expected output here in the question.

  • makes group by those fields

  • Doing group by of TR.CODPARC, TR.NOMEPARC, TB.CODVEND, TV.NICKNAME, TV.AD_CARTAOCAMP says that it is not a group by and putting distinct operation does not accept select.

1 answer

0

I believe that what you want, and what you have tried to explain in the comments, is:

SELECT TR.CODPARC, TR.NOMEPARC, TB.CODVEND, TV.APELIDO, TV.AD_CARTAOCAMP, SUM(TP.AD_CAMPLENTE), SUM(TP.AD_CAMPPONTOS)
FROM TGFCAB TB, TGFITE TE, TGFPRO TP, TGFPAR TR, TGFVEN TV
Where Tb.Nunota = Te.Nunota 
AND TB.CODVEND = TV.CODVEND
AND TP.CODPROD = TE.CODPROD
AND TB.CODPARC = TR.CODPARC
And Tb.Tipmov = 'P'
AND TB.CODTIPOPER IN (3100, 3102, 3105)
AND TB.DTNEG >= :PERIODO.INI
AND TB.DTNEG <= :PERIODO.FIN
AND TV.AD_CARTAOCAMP IS NOT NULL
GROUP BY TR.CODPARC, TR.NOMEPARC, TB.CODVEND, TV.APELIDO, TV.AD_CARTAOCAMP
ORDER BY TB.KLKCLBOSE'
  • When using this query the following error occurs : "ORA-00979: is not a GROUP BY expression"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.