How to select multiple avg(column) in one select statement in MySql stored procedure?

224 views Asked by At

I find when I select one avg(column) into a variable,it is OK.But when I select more than one avg into a variable,it is wrong.I do not want to write it twice,how to fixed it?

   //work well
  SELECT 
  avg(MathPoint) into  MathPoint 
 from student
 where  sex=1

 SELECT 
  avg(EnglishPoint) into  EnglishPoint
 from student
 where  sex=1

//do not work 
  SELECT  
 avg(EnglishPoint) into  EnglishPoint,
 avg(MathPoint) into  MathPoint,
 from student
 where  sex=1
1

There are 1 answers

0
Ravinder Reddy On BEST ANSWER

You have syntax error on INTO usage.

INTO should follow all variable names together after selecting fields.

Example:

SELECT  
       avg(EnglishPoint), avg(MathPoint)
  into EnglishPoint, MathPoint
  from student
 where  sex=1

Documentation: