Is there a way to use the values of a column as headers?

30
February 12, 2019, at 12:50 PM

I'm trying to make a table that shows all students and their grades by course. So far I have something like this

Name | Lastname | Course | Final Grade
Jhon | Smithens | Course1 | 98
Jhon | Smithens | Course2 | 78
Mary | Smithens | Course1 | 65
Mary | Smithens | Course1 | 94

I'm using Moodle 3.6 with the plugin configurable reports. MySQL.

This is my query.

SELECT u.firstname             AS 'First Name', 
       u.lastname              AS 'Last Name', 
       c.fullname              AS 'Course', 
       Round(gg.finalgrade, 2) AS 'Final Grade' 
FROM   prefix_course AS c 
       JOIN prefix_context AS ctx 
         ON c.id = ctx.instanceid 
       JOIN prefix_role_assignments AS ra 
         ON ra.contextid = ctx.id 
       JOIN prefix_user AS u 
         ON u.id = ra.userid 
       JOIN prefix_grade_grades AS gg 
         ON gg.userid = u.id 
       JOIN prefix_grade_items AS gi 
         ON gi.id = gg.itemid 
       JOIN prefix_course_categories AS cc 
         ON cc.id = c.category 
WHERE  gi.courseid = c.id 
       AND gi.itemtype = 'course' 
       AND ra.roleid = 5 
ORDER  BY u.firstname, 
          u.lastname, 
          c.id DESC, 
          gi.itemname 

What I need is something Like this

Name | LastName | C1 | C2     
Jhon | Smithens | 98 | 78    
Mary | Smithens | 65 | 94
READ ALSO
Rails group also returns count of duplicate rows

Rails group also returns count of duplicate rows

TLDR - I am trying to do group on this returned collection of distinct rowsBut for some reason, it also counts rows with duplicate procurement_id

20
Query to update particular column field in SQL

Query to update particular column field in SQL

I tried the following queries to change the column field of the table 'role' from 'Admin' to 'Administrator'I am not informed about the values of id

35
How to query a date using strftime to format

How to query a date using strftime to format

I am trying to grab all the records for the monthThe string I have to query with is in this format 2019-01-12

28
Extract data from a database if a specific value in is followed by a another specific value

Extract data from a database if a specific value in is followed by a another specific value

I have a database in MySQL where one of the columns consists of different types of events and I want to extract specific data to pythonFor example:

48