sql >> Databasteknik >  >> RDS >> Mysql

Hur man omvandlar resultaten av en SQL-fråga till en HTML-tabell med specifikt format

Prova detta:

SELECT A.month, 
       SUM(CASE WHEN A.department = 'Physics' AND A.property = 'undergraduate' THEN A.total_no_students ELSE 0 END) AS Physics_undergraduate, 
       SUM(CASE WHEN A.department = 'Physics' AND A.property = 'postgraduate' THEN A.total_no_students ELSE 0 END) AS Physics_postgraduate, 
       SUM(CASE WHEN A.department = 'Architecture' AND A.property = 'undergraduate' THEN A.total_no_students ELSE 0 END) AS Architecture_undergraduate, 
       SUM(CASE WHEN A.department = 'Architecture' AND A.property = 'postgraduate' THEN A.total_no_students ELSE 0 END) AS Architecture_postgraduate, 
       SUM(CASE WHEN A.department = 'Biology' AND A.property = 'undergraduate' THEN A.total_no_students ELSE 0 END) AS Biology_undergraduate, 
       SUM(CASE WHEN A.department = 'Biology' AND A.property = 'postgraduate' THEN A.total_no_students ELSE 0 END) AS Biology_postgraduate
FROM (...Your Existing Query...) AS A 
GROUP BY A.month



  1. Kolumnantal matchar inte värderäkning på rad 1

  2. Tidszon medveten datetime till sträng?

  3. Strategi för att förbättra Oracle DELETE-prestanda

  4. Rekursiv funktion för kommentar och svar PHP-applikation