sql >> Database teknologi >  >> RDS >> Mysql

Sådan transformeres resultaterne af en sql-forespørgsel til en html-tabel med specifikt format

Prøv dette:

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. Hvordan ændres BRUGERNAVN og ADGANGSKODE i MySQL?

  2. højre join er lig med venstre join?

  3. Hvordan listes oplysninger om alle Alfrescos filer (Postgres SQL)?

  4. Hvordan opretter jeg en passthrough-forespørgsel i adgang ved hjælp af en DSN-fri forbindelse?