I'm trying to fetch a report. Below is the query which I tried.
SELECT
u.firstname AS FIRST,
u.lastname AS LAST,
c.fullname AS Course,
st.attempt AS Attempt,
st.value AS STATUS
FROM prefix_scorm_scoes_track AS st
JOIN prefix_user AS u ON st.userid=u.id
JOIN prefix_user_info_data AS uid ON uid.userid = u.id
JOIN prefix_scorm AS sc ON sc.id=st.scormid
JOIN prefix_course AS c ON c.id=sc.course
WHERE st.element='cmi.core.total_time' AND st.element='cmi.core.lesson_status' and c.id=1
UNION
SELECT
user2.firstname AS FIRST,
user2.lastname AS LAST,
c.fullname AS Course,
"-" AS Attempt,
"not_started" AS STATUS
FROM prefix_user_enrolments AS ue
JOIN prefix_enrol AS e ON e.id = ue.enrolid
JOIN prefix_course AS c ON c.id = e.courseid
JOIN prefix_user AS user2 ON user2 .id = ue.userid
JOIN prefix_user_info_data AS uid ON uid.userid = user2.id
JOIN prefix_scorm AS sc ON sc.course=c.id
LEFT JOIN prefix_scorm_scoes_track AS st ON st.scormid=sc.id AND st.userid=user2.id
WHERE st.timemodified IS NULL AND c.id=1
ORDER BY Course, LAST, FIRST, Attempt
What I'm looking for is, I want the values of cmi.core.total_time and cmi.core.lesson_status in two columns. But in the database it's stored as row:
How Can I get the values of lesson and total time in two columns?
Appreciate your help!
Updated query:
SELECT
u.firstname AS FIRST,
u.lastname AS LAST,
c.fullname AS Course,
st.attempt AS Attempt,
(case when st.element = 'cmi.core.total_time' then st.value else NULL end) as timespent,
(case when st.element = 'cmi.core.lesson_status' then st.value else NULL end) as status
FROM prefix_scorm_scoes_track AS st
JOIN prefix_user AS u ON st.userid=u.id
JOIN prefix_user_info_data AS uid ON uid.userid = u.id
JOIN prefix_scorm AS sc ON sc.id=st.scormid
JOIN prefix_course AS c ON c.id=sc.course
WHERE c.id=1
UNION
SELECT
user2.firstname AS FIRST,
user2.lastname AS LAST,
c.fullname AS Course,
"-" AS Attempt,
"not_started" AS STATUS,
"-" AS DATE
FROM prefix_user_enrolments AS ue
JOIN prefix_enrol AS e ON e.id = ue.enrolid
JOIN prefix_course AS c ON c.id = e.courseid
JOIN prefix_user AS user2 ON user2 .id = ue.userid
JOIN prefix_user_info_data AS uid ON uid.userid = user2.id
JOIN prefix_scorm AS sc ON sc.course=c.id
LEFT JOIN prefix_scorm_scoes_track AS st ON st.scormid=sc.id AND st.userid=user2.id
WHERE c.id=1
But then I'm getting the values in multiple rows instead of single row: enter image description here