How to create horizontal columns from rows in MYSQL?
Sorry if I asked this dumb question as it puzzled me how to do such for several days.
I have a table in MySQL named Grades.
Now, what I want to do is to make an output like this one.
Is there an SQL to do such? Thank you so much in advance.
You can apply a case/when and group by the student and the class. If you want only a single person, just apply a where clause... or even if you want all students for a class, or a given school year... etc.
SELECT g.studNumber, g.subjCode, MAX( case when g.period = 1 then g.grade else 0 end ) as 1st_period, MAX( case when g.period = 2 then g.grade else 0 end ) as 2nd_period, MAX( case when g.period = 3 then g.grade else 0 end ) as 3rd_period, MAX( case when g.period = 4 then g.grade else 0 end ) as 4th_period, AVG( g.grade ) as Ave from Grades g group by g.studNumber, g.subjCode
- A Linux, Apache, MySQL, PHP (LAMP) stack is a combination of open source software that is typically installed together to enable a server to host dynamic […]
- MySQL is an the most popular open-source database management system, in most of hosting company its has been bundle by LAMP(Linux, Apache, MySQL, PHP/Python/Perl) stack. Another alternative […]
- MySQL is the world’s most popular open-source database. Despite its powerful features, MySQL is simple to set up and easy to use. Below are some instructions […]