Skip to content
Advertisement

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.

Advertisement

Answer

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
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement