Boa Tarde!
Estou tentando elaborar um relatorio que traga como retorno o total de vendas deduzido das devolucoes de vendas, por mes/cliente. Segue a sentença SQL que elaborei, porem ela nao esta funcionando, retornando a mensage "A Sentença SQL nao é valida! General SQL error. Column 'TMOV.CODTMV' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY"
Se coloco TMOV.CODTMV dentro da funcao GRoup by, ele da time out e nao executa a SQL
SELECT fcfo.nome,
(case when tmov.codtmv in ('1.2.16','1.2.17','1.2.26','1.2.27') then sum(tmov.valorliquido)*-1 end) [Devolucao],
(case when tmov.codtmv in ('2.2.10') then sum(tmov.valorliquido) end) [Vendas],
(case when month(tmov.dataemissao)=01 then 'Janeiro'
when month(tmov.dataemissao)=02 then 'Fevereiro'
when month(tmov.dataemissao)=03 then 'Marco'
when month(tmov.dataemissao)=04 then 'Abril'
when month(tmov.dataemissao)=05 then 'Maio'
when month(tmov.dataemissao)=06 then 'Junho'
when month(tmov.dataemissao)=07 then 'Julho'
when month(tmov.dataemissao)=08 then 'Agosto'
when month(tmov.dataemissao)=09 then 'Setembro'
when month(tmov.dataemissao)=10 then 'Outubro'
when month(tmov.dataemissao)=11 then 'Novembro'
when month(tmov.dataemissao)=12 then 'Decembro'
end)
FROM tmov,fcfo
where TMOV.CODTMV in('2.2.10','1.2.16','1.2.17','1.2.26','1.2.27')
and year(tmov.dataemissao)=2008
AND TMOV.STATUS<>'C'
group by nome, month(tmov.dataemissao),tmov.codtmv
order by nome
obrigada pela ajuda,
Marli