Results 1 to 3 of 3

Thread: Mysql pivot how

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2019
    Posts
    44

    Mysql pivot how

    I am using mysql db. I want to learn how to pivot data. Tia

  2. #2
    Member
    Join Date
    Jul 2019
    Location
    Ahmedabad
    Posts
    57

    Re: Mysql pivot how

    pivot data is the process of aggregating or moving rows of data into columns

    You can try this query:

    Code:
    CREATE TABLE Exams (
            pkey int(11) NOT NULL auto_increment,
            name varchar(15),
            exam int,
            score int,
            PRIMARY KEY  (pkey)
          );
    
          insert into Exams (name,exam,score) values ('Name1',1,75);
          insert into Exams (name,exam,score) values ('Name1',2,77);
          insert into Exams (name,exam,score) values ('Name1',3,78);
          insert into Exams  (name,exam,score) values ('Name1',4,80);
    
          insert into Exams (name,exam,score) values ('Name2',1,90);
          insert into Exams (name,exam,score) values ('Name2',2,97);
          insert into Exams (name,exam,score) values ('Name2',3,98);
          insert into Exams (name,exam,score) values ('Name2',4,99);
    
          
          select name,
          sum(score*(1-abs(sign(exam-1)))) as exam1,
          sum(score*(1-abs(sign(exam-2)))) as exam2,
          sum(score*(1-abs(sign(exam-3)))) as exam3,
          sum(score*(1-abs(sign(exam-4)))) as exam4
          from exams group by name;
    < advertising removed by moderator >

  3. #3

    Re: Mysql pivot how

    hello...
    from below link is helpful for you to learn pivot in MySQL.
    https://www.c-sharpcorner.com/Upload...20need%20them.
    < advertising removed by moderator >

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width