title: Find difference between two fields as columns in a table
body: <p>I have the following sql below</p>
  
  <pre><code>SELECT
  ttstudent.ttstudentid,
  ttstudent.studentid,
  ttstudent.subjectid,
  ttstudent.classnumber,
  ttstudent.classid,
  concat(student.fn, " ", student.sn) AS Student,
  SUM(If(ondemand.cycle="Feb7" and ondemand.type="Numeracy", ondemand.Score, NULL)) AS `Yr7 Feb`,
  SUM(If(ondemand.cycle="Jul7" and ondemand.type="Numeracy", ondemand.Score, NULL)) AS `Yr7 July`,
  SUM(If(ondemand.cycle="Feb8" and ondemand.type="Numeracy", ondemand.Score, NULL)) AS `Yr8 Feb`,
  SUM(If(ondemand.cycle="Jul8" and ondemand.type="Numeracy", ondemand.Score, NULL)) AS `Yr8 July`,
  SUM(If(ondemand.cycle="Feb9" and ondemand.type="Numeracy", ondemand.Score, NULL)) AS `Yr9 Feb`,
  SUM(If(ondemand.cycle="Jul9" and ondemand.type="Numeracy", ondemand.Score, NULL)) AS `Yr9 July`,
  SUM(If(ondemand.cycle="Feb10" and ondemand.type="Numeracy", ondemand.Score, NULL)) AS `Yr10 Feb`,
  SUM(If(ondemand.cycle="Jul10" and ondemand.type="Numeracy", ondemand.Score, NULL)) AS `Yr10 Aug`,
  ondemand.Student_ID
  FROM ttstudent
  INNER JOIN student ON ttstudent.studentid = student.code
  INNER JOIN ondemand ON ttstudent.studentid = ondemand.Student_ID
  GROUP BY ondemand.Student_ID
  </code></pre>
  
  <p>This generates for about 25 people a columnar list with the last column the calculated field that finds the difference between the last 2 values in the table. The scores are time stamped.</p>
  
  <pre><code>CODE |Year7Feb|Year7Jul|Year8Feb|Year8Jul|Year9Feb|Year9Jul| Year10Feb| Growth
  abe1 |    2.3 |   2.9  |        |        |        |        |          |   .6
  bas1 |        |        |   3.5  |   3.7  |        |        |          |   .2
  cod  |        |        |        |        |        |  4.5   |    5.2   |   .7
  </code></pre>
  
  <p>What I would like to do is a add another column which would take the last two scores from each user (whichever column it is in) and find the difference. I would call this column growth.</p>
  
  <p>I am struggling with what to use other than max. Any ideas?</p>