Jump to content
GGM

[Resolvido] Ajuda com SUM()

Recommended Posts

Pessoal, tenho a seguinte tabela, e quero fazer as seguintes somas:

sum().png.519cef74aa4ee453fdbb9a3d0f039694.png

Utilizando a query abaixo, a mesma me retorna o valor 16, no entanto eu desejo obter separadamente os valores 9 e 7:

SELECT SUM(e1.`quantidade_erros`) AS total FROM erro e1, erro e2 WHERE e1.`id_erro` <> e2.`id_erro` AND e1.`fk_id_questionario` = e2.`fk_id_questionario` AND e1.`fk_id_turma` = e2.`fk_id_turma`

Alguma dica?

Share this post


Link to post
Share on other sites
SELECT e1.`fk_id_questionario`, SUM(e1.`quantidade_erros`) AS total
FROM erro e1, erro e2
WHERE e1.`id_erro` <> e2.`id_erro`
AND e1.`fk_id_questionario` = e2.`fk_id_questionario`
AND e1.`fk_id_turma` = e2.`fk_id_turma`
group by e1.`fk_id_questionario`

Pelo que entendi ...

Share this post


Link to post
Share on other sites
14 horas atrás, Motta disse:

SELECT e1.`fk_id_questionario`, SUM(e1.`quantidade_erros`) AS total
FROM erro e1, erro e2
WHERE e1.`id_erro` <> e2.`id_erro`
AND e1.`fk_id_questionario` = e2.`fk_id_questionario`
AND e1.`fk_id_turma` = e2.`fk_id_turma`
group by e1.`fk_id_questionario`

Pelo que entendi ...

Muitíssimo obrigado, Motta. Deu certinho. Valeu!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

Ao usar o fórum, você concorda com nossos Terms of Use.