1
Have the query below.
SELECT
'A. ABERTOS' QUANTIDADE,
(SELECT SUM(S)
FROM
(SELECT COUNT(*) S
FROM VW_SOLICITACAO_DETALHE VW
INNER JOIN SOLICITACAO SOL ON SOL.ID_SOLICITACAO = VW.ID_SOLICITACAO
WHERE (VW.COD_TIPO_SERVICO IN ('MC','OP') OR (VW.COD_TIPO_SERVICO IN ('SA') AND SOL.IND_DPU = 'S'))
AND YEAR(VW.DATA_ABERTURA_SOLICITACAO) = ('2014') AND MONTH(VW.DATA_ABERTURA_SOLICITACAO) = 1
UNION ALL
SELECT COUNT(*) S
FROM APROPRIACAO APR
INNER JOIN ATIVIDADE ATIV ON ATIV.ID_ATIVIDADE = APR.ID_ATIVIDADE
INNER JOIN SOLICITACAO SOL ON SOL.ID_SOLICITACAO = ATIV.ID_SOLICITACAO
INNER JOIN SITUACAO_SOLICITACAO TSOL ON TSOL.ID_SITUACAO_SOLICITACAO = SOL.ID_SITUACAO_SOLICITACAO
INNER JOIN CLIENTE CLI ON CLI.ID_CLIENTE = SOL.ID_CLIENTE
WHERE YEAR(APR.DATA_APROPRIACAO) = ('2014') AND MONTH(APR.DATA_APROPRIACAO) = 2
AND TSOL.DSC_SITUACAO_SOLICITACAO NOT IN ('Desenvolvimento Cancelado')
AND SOL.COD_SOLICITACAO NOT LIKE 'SA%'
GROUP BY CLI.ID_CLIENTE
) ITEM
) JAN,
(SELECT SUM(S)
FROM
(SELECT COUNT(*) S
FROM VW_SOLICITACAO_DETALHE VW
INNER JOIN SOLICITACAO SOL ON SOL.ID_SOLICITACAO = VW.ID_SOLICITACAO
WHERE (VW.COD_TIPO_SERVICO IN ('MC','OP') OR (VW.COD_TIPO_SERVICO IN ('SA') AND SOL.IND_DPU = 'S'))
AND YEAR(VW.DATA_ABERTURA_SOLICITACAO) = ('2014') AND MONTH(VW.DATA_ABERTURA_SOLICITACAO) = 2
UNION ALL
SELECT COUNT(*) S
FROM APROPRIACAO APR
INNER JOIN ATIVIDADE ATIV ON ATIV.ID_ATIVIDADE = APR.ID_ATIVIDADE
INNER JOIN SOLICITACAO SOL ON SOL.ID_SOLICITACAO = ATIV.ID_SOLICITACAO
INNER JOIN SITUACAO_SOLICITACAO TSOL ON TSOL.ID_SITUACAO_SOLICITACAO = SOL.ID_SITUACAO_SOLICITACAO
INNER JOIN CLIENTE CLI ON CLI.ID_CLIENTE = SOL.ID_CLIENTE
WHERE YEAR(APR.DATA_APROPRIACAO) = ('2014') AND MONTH(APR.DATA_APROPRIACAO) = 2
AND TSOL.DSC_SITUACAO_SOLICITACAO NOT IN ('Desenvolvimento Cancelado')
AND SOL.COD_SOLICITACAO NOT LIKE 'SA%'
GROUP BY CLI.ID_CLIENTE
)
)
Her return is this:
I have already grouped it by client, but I cannot put the CLIENT as part of the select, as I do for it to return grouped by the client?
Thank you
There is a column missing in the output, no !? You would have to group by CLIENT in the Queries below and then display in the query above. The question is whether the query can be improved.
– Motta
Already managed to solve?
– David