0

My attendance table has the following fields:

attendance 
  studentID, 
  cDate, 
  isPresent

The isPresent field contains 1 for present, 0 for absent.

I need a pivot query for final attendance report that will have header

studentID, date1, date2, date3..., total

and each data row will contain something like:

St001, 1,1,0,1... 3

date1, date2 etc. will be found from the data.

Now I am exporting the data into an excel file for the report.

But I want to do it in MySQL.

Can anyone help me on creating the pivot query.

I read many articles on it but with not much clear conception.

Bill Karwin
  • 538,548
  • 86
  • 673
  • 828
  • I'm not clear what your question is. – Strawberry Aug 23 '20 at 18:24
  • 1
    see my answer hw https://stackoverflow.com/questions/62711642/mysql-mariadb-create-a-pivot-table-view/62712027#62712027 and try to adapt it to your needs if tít doesn't work – nbk Aug 23 '20 at 18:24
  • Very easy with excel, don't complicate! Or write some code to do the logic. Still you can check out https://stackoverflow.com/questions/3561881/mysql-pivot-counting to do it in MySQL! – Onur Baştürk Aug 23 '20 at 20:48

1 Answers1

0

Here's a stored procedure that will create the pivot code and execute it:

http://mysql.rjweb.org/doc.php/pivot

Rick James
  • 135,179
  • 13
  • 127
  • 222