sql - How to create horizontal columns from rows in MYSQL? -


sorry if asked dumb question puzzled me how such several days.

i have table in mysql named grades. enter image description here

now, want make output one. enter image description here

is there sql such? thank in advance.

you can apply case/when , group student , class. if want single person, apply clause... or if want students class, or given school year... etc.

select       g.studnumber,       g.subjcode,       max( case when g.period = 1 g.grade else 0 end ) 1st_period,       max( case when g.period = 2 g.grade else 0 end ) 2nd_period,       max( case when g.period = 3 g.grade else 0 end ) 3rd_period,       max( case when g.period = 4 g.grade else 0 end ) 4th_period,       avg( g.grade ) ave          grades g    group        g.studnumber,       g.subjcode 

Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -