Home > Software engineering >  MySQL : calculate SUM of a Query
MySQL : calculate SUM of a Query

Time:02-11

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.

CodePudding user response:

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
  • Related