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. 
now, want make output one. 
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
Post a Comment