-2

I would like to transpose attendance sql table as below

Below Mysql table data

To the following

enter image description here

Please help me here

Thanks Sara

user1283333
  • 137
  • 1
  • 5

1 Answers1

1

In MySQL, you would do this using conditional aggregation:

select pname,
       sum(case when weekday = 'Monday' then days else 0 end) as M,
       . . .,
       sum(days) as Total
from  t
group by pname;

Put the logic in the for the rest of the weekdays where . . . is.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786