Mysql – SELECT , GROUP AND DISPLAY IN TABULAR FORM

MySQL

DATA TABLE

I Have a table as above. How can I get an output (as shown below) with a single mysql query.

enter image description here

Best Answer

SELECT location,
       AVG(CASE WHEN qtr = 'Q1' THEN achievement END) q1-average,
       AVG(CASE WHEN qtr = 'Q2' THEN achievement END) q2-average
FROM sourcetable
-- WHERE year = '2018'
GROUP BY location;