I created a sql select query, but I cannot get the records to display correctly.
Table:
gradeid | usrname | reviewmonth | program | total_score | pae
--------------------------------------------------------------
151 | smithj | 2 | math | 100% | 100%
152 | smithj | 2 | math | 95% | 100%
153 | smithj | 3 | math | 80% | 100%
154 | jonesm | 3 | math | 79% | 79%
155 | jonesj | 2 | art | 100% | 100%
The query that I created to display the information is
SELECT reviewmonth,
ROUND(AVG( IF(pae = 79, (IF(pae < total_score, pae,total_score)),total_score)),2) AS January
FROM vwscore
WHERE program = 'Math' AND reviewmonth = 1
UNION ALL
SELECT reviewmonth,
ROUND(AVG( IF(pae = 79, (IF(pae < total_score, pae,total_score)),total_score)),2) AS February
FROM vwscore
WHERE program = 'Math' AND reviewmonth = 2
UNION ALL
SELECT reviewmonth,
ROUND(AVG( IF(pae = 79, (IF(pae < total_score, pae,total_score)),total_score)),2) AS March
FROM vwscore
WHERE program = 'Math' AND reviewmonth = 3
UNION ALL
The query returns: Unfortunately I need to display the records horizontally.
reviewmonth | January
----------------------
1 | 91.94
2 | 94.86
3 | 89.89
Desired outcome:
January | February | March
--------------------------
91.94| 94.86 | 89.89
I tried different queries to display the answer. I tried using CASE, but it seemed to only display 1 record. Thanks for all your help!