Transpose rows data into columns in MYSQL Please help me with the scrip that can change table1 into table2 given in the post. I wish to change the rows data into columns
Please provide Data as Text, your image, is for an ocr not really good enough


CREATE TABLE table1 (
  `regno` VARCHAR(6),
  `subject` VARCHAR(16),
  `grade` VARCHAR(2)
);

INSERT INTO table1
  (`regno`, `subject`, `grade`)
VALUES
  ('7007gd', 'mathematics', 'C6'),
  ('7007gd', 'english language', 'CS'),
  ('7007gd', 'economics', 'C5'),
  ('7007gd', 'government', '83'),
  ('7007gd', 'biology', 'C6'),
  ('7010gd', 'mathematics', 'C6'),
  ('7010gd', 'english language', 'C5'),
  ('7010gd', 'economics', 'C5'),
  ('7010gd', 'government', 'C5'),
  ('7010gd', 'biology', 'C5'),
  ('70151f', 'mathematics', 'C6'),
  ('70151f', 'english language', 'C5'),
  ('70151f', 'economics', 'C6'),
  ('70151f', 'government', 'C5'),
  ('70151f', 'biology', 'C5'),
  ('70151f', 'chemistry', 'C5'),
  ('70151f', 'physics', '83');




SET @sql = NULL;
SELECT
  GROUP_CONCAT(DISTINCT
               CONCAT('MAX(IF(`subject` = &quot;', `subject`,'&quot;, `grade`,&quot;&quot;)) AS &quot;',`subject`,'&quot;')
              ) INTO @sql
FROM table1;


SET @sql = CONCAT('SELECT  `regno`,  ', @sql, ' 
                  FROM table1 s
                 GROUP BY s.`regno`
                 ORDER BY s.`regno`');
#SELECT @sql;
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE stmt;


regno  | biology | chemistry | economics | english language | government | mathematics | physics
:----- | :------ | :-------- | :-------- | :--------------- | :--------- | :---------- | :------
7007gd | C6      |           | C5        | CS               | 83         | C6          |        
7010gd | C5      |           | C5        | C5               | C5         | C6          |        
70151f | C5      | C5        | C6        | C5               | C5         | C6          | 83     


db&lt;&gt;fiddle here