Search code examples
mysqldynamic-pivot

MYSQL attendance by attendance date


I want to make an attendance system in mysql. like two different dates lets say. 2017-12-21 and 2017-12-23

if i have

my table test looks like this. name date attendance comment

Person 1 2017-12-21 Yes comment
Person 1 2017-12-23 Yes comment
Person 2 2017-12-21 No  comment 
Person 2 2017-12-23 Yes comment

And the result i want is

-----2017-12-21----------------2017-12-23-----------
-----Person 1 Yes comment ---- Person 1 Yes comment
-----Person 2 NO  comment ---- Person 2 Yes comment
----------------------------------------------------

Think leftjoin will work but to hard for me someone can help? Thanks.


Solution

  • Its for a sports team. I have this my database now i have tested many ways to do it. Group_Contact wont work.

    CREATE TABLE IF NOT EXISTS `attendance` (
          `playerid` int(11) NOT NULL,
          `idnumber` int(11) NOT NULL AUTO_INCREMENT,
          `name` varchar(255) NOT NULL,
          `date` date NOT NULL,
          `attendance` varchar(10) NOT NULL,
          `comment` varchar(1023) NOT NULL,
          PRIMARY KEY (`playerid`)
    );
    

    This is the result i want use it in php later. (a = attendance c = comment)

    attendance| Name     | a2017-12-21|c2017-12-21|a2017-12-23|c2017-12-23|
    
              | Person 1 |     YES    |   Comment |     NO    |  Comment  |
    
              | Person 2 |     YES    |   Comment |    YES    |  Comment  |