0
I am using the code below to make the column of the month of January, but I could not find a way to return the month of February to the side.
SELECT
CASE
WHEN CODGRUPOPROD LIKE '20%'
THEN 'TALHA CORRENTE'
WHEN CODGRUPOPROD LIKE '21%'
THEN 'TALHA CABO DE AÇO'
WHEN CODGRUPOPROD LIKE '22%'
THEN 'PONTE ROLANTE'
WHEN CODGRUPOPROD LIKE '23%'
THEN 'SISTEMA LCS'
WHEN CODGRUPOPROD LIKE '25%'
THEN 'MONOVIA'
WHEN CODGRUPOPROD LIKE '27%'
THEN 'GUINDASTE'
ELSE 'OUTROS'
END AS 'EQUIPAMENTO',
SUM(VLRUNIT * ITE.QTDNEG) AS JANEIRO
FROM
TGFCAB CAB
INNER JOIN TGFITE ITE ON CAB.NUNOTA = ITE.NUNOTA
INNER JOIN TGFPRO PRO ON ITE.CODPROD = PRO.CODPROD
WHERE
CAB.AD_LIBERACAO_INTERNA BETWEEN '01/01/2021' AND '31/01/2021' AND CODTIPOPER IN (39,87,3100) AND AD_PEDIDO_CANCELADO IS NULL
GROUP BY
CASE
WHEN CODGRUPOPROD LIKE '20%'
THEN 'TALHA CORRENTE'
WHEN CODGRUPOPROD LIKE '21%'
THEN 'TALHA CABO DE AÇO'
WHEN CODGRUPOPROD LIKE '22%'
THEN 'PONTE ROLANTE'
WHEN CODGRUPOPROD LIKE '23%'
THEN 'SISTEMA LCS'
WHEN CODGRUPOPROD LIKE '25%'
THEN 'MONOVIA'
WHEN CODGRUPOPROD LIKE '27%'
THEN 'GUINDASTE'
ELSE 'OUTROS'
END
THE RESULT IS THE RESULT OF THE IMAGE BELOW
I guess I could group just by code without the case:
GROUP BY CODGRUPOPROD
. Over the month, you also need to group to bring separate values, for example add to select and group byYEAR(CAB.AD_LIBERACAO_INTERNA), MONTH(CAB.AD_LIBERACAO_INTERNA)
– Ricardo Pontual
About the case in codgrupoprod is the question of the description of the group, now about the month, it would have to group the value , within that month in the" column" , when I use Month it group by row.
– Roberto Hawks
to help more need to have an example of the data... can add in question or mount an example of sqlfiddle.com for example?
– Ricardo Pontual