title: How can I assign value to a variable using aggregate function in mysql?
body: <p>This is my table structure and data.</p>
  
  <pre><code>create table StudentInformation
  (
      sId INT(5),
      name VARCHAR(50),
      sClass VARCHAR(10),
      maths INT(5),
      physics INT(5),
      chemistry INT(5)
  );
  
  INSERT INTO StudentInformation
  values
  (1, 'Jai', '11th', 60, 75, 65),
  (2, 'Leela', '12th', 91, 87, 94),
  (3, 'Suresh', '11th', 75, 68, 70),
  (4, 'Ramesh', '11th', 50, 67, 55),
  (5, 'Janki', '12th', 78, 89, 78),
  (6, 'Lalu', '12th', 30, 38, 45),
  (7, 'Amit', '11th', 91, 95, 93),
  (8, 'Komal', '11th', 66, 78, 74),
  (9, 'Sanjay', '12th', 25, 40, 35);
  </code></pre>
  
  <p>Now I want to calculate average marks for each class.<br>
  I have tried this query :</p>
  
  <pre><code>SELECT
  sClass class,
  @var := sum(maths+physics+chemistry)/(count(sid)*3) as avgMarksPerSubject,
  @var as variableValue,
  count(sid) as numberOfStudents
  FROM StudentInformation
  #where @var &gt; 65
  group by sClass;
  </code></pre>
  
  <p>Use of variable is compulsory here as this is just an example of my actual task.<br>
  Now I would like to have those records which have more than 65 marks.<br>
  Is it possible by using variable in <code>WHERE</code> clause ?<br>
  I am not getting actual data in <code>@var</code>, how can I use it in <code>WHERE</code> clause ?<br>
  You can try sql query <a href="http://sqlfiddle.com/#!2/bfde9/14" rel="nofollow">here</a>.<br>
  Any suggestion ?<br>
  Thanks</p>