0
I need to present a report and my query is this:
SELECT
f.nome,
count(hv.id) as qtdvendas,
sum(hv.total) as totalvendido,
sum(iv.valor_venda - iv.valor_compra) as lucrototal,
ROUND(sum(iv.valor_venda - iv.valor_compra)/count(hv.id), 2) as lucromedio,
ROUND(sum(hv.total) * c.comissao / 100, 2) comissao,
IF(c.meta>=sum(hv.total),ROUND(c.meta * c.premio / 100, 2),0.00) as premio,
ROUND(sum(hv.total) * 100 /c.meta, 2) as percmeta,
ROUND((sum(hv.total) * c.comissao / 100 ) + (c.meta * c.premio / 100), 2) as comprem
from usuarios f
left join historico_venda hv on hv.id_usuario = f.id
left join itens_venda iv on iv.id_venda = hv.id
left join comissao c on c.id_usuario = f.id
where
c.mes='201801'
AND hv.dia >= '20180101'
AND hv.dia <= '20180131'
AND f.acesso='1' AND f.ativo='1' AND f.id_grupo='1'
order by totalvendido DESC, percmeta DESC
he’s giving a group by error, how would this group by?? tried in several ways but it didn’t work.
What a mistake you’re making?
– Roberto de Campos
he says that ta missing a grouper term but I tried coloka group by e dai da pau in the table
– Jasar Orion