I need to display 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 is giving a group by error, what would this group by ?? I tried it in many ways but it did not work.