ossama assaghir
ossama assaghir

Reputation: 308

MySQL : calculate SUM of a Query

i have a mysql query that looks like this :

select  (pondérée_note*100)/pondérée as b 
from answers 
where answers.question_id in (select id 
                              from questions 
                              where categorie_id = 3) 
  and user_id = 5

The query returns a table b :

b
50
50
13
25

I want to do the sum of those values By

select SUM(query);

but it doesn't work because of a syntax error.

is it possible to sum a query like this ? Thanks.

Upvotes: 0

Views: 40

Answers (1)

Zakaria
Zakaria

Reputation: 4806

Try this:

select  sum((pondérée_note*100)/pondérée) as sumb 
from answers 
where answers.question_id in 
(select id from questions where categorie_id = 3) and user_id = 5

Upvotes: 1

Related Questions