I found the UNION ALL option but the results are shown below on the other, I would like you to create a column for each discipline
I have these two queries and I would like to join the two, the difference between them is that one has a column called MediaMT
and in the other MediaPT
, there is also a difference between the two in a row of where, one is SUBSTR(qc.name,8) = "MATEMATICA"
and in the other it SUBSTR(qc.name,8) = "PORTUGUES"
would like that in the result these two columns would be shown side by side, would be:
MediaPT | MediaMT | MediaGeneral ...
Follow the queries:
Query for MediaPT
select avg(IFNULL(fraction, 0))*10 as MediaPT, gg.finalgrade as NotaGeral, u.firstname as Aluno, u.username as Usuario, u.lastname as siem, qas.userid, u.department as Turma, u.institution as Escola, qc.name as cat
FROM mdl_question_attempt_steps qas
inner join mdl_user u on u.id=qas.userid
INNER JOIN mdl_question_attempts qa ON qa.id=qas.questionattemptid
INNER JOIN mdl_question q On q.id=qa.questionid
inner join mdl_grade_grades gg on gg.userid=u.id
INNER JOIN mdl_grade_items gi ON gi.'id' = gg.'itemid'
INNER JOIN mdl_quiz_slots qs ON qs.questionid=qa.questionid
Inner Join mdl_quiz quiz ON quiz.id=qs.quizid
inner join mdl_question_categories qc ON qc.id=q.category
where substring(u.department,2,1) = 4
and substr(gi.itemname,1)= 4
and substr(gi.itemname,-1)= 1
and substr(quiz.ano,1,4)=2018
and u.lastname=213
and substr(quiz.name,1)= 4
and substr(quiz.name,-1)= 1
AND itemtype = "mod"
AND itemmodule = "quiz"
AND finalgrade != "NULL"
and qas.state!="todo"
and qas.state!="complete"
and aggregationstatus = "used"
and SUBSTR(qc.name,8) = "PORTUGUES"
and qs.slot=qa.slot
group by turma, u.id
ORDER BY turma ASC, 'Aluno' ASC
Query for MediaMT
select avg(IFNULL(fraction, 0))*10 as MediaMT, gg.finalgrade as NotaGeral, u.firstname as Aluno, u.username as Usuario, u.lastname as siem, qas.userid, u.department as Turma, u.institution as Escola, qc.name as cat
FROM mdl_question_attempt_steps qas
inner join mdl_user u on u.id=qas.userid
INNER JOIN mdl_question_attempts qa ON qa.id=qas.questionattemptid
INNER JOIN mdl_question q On q.id=qa.questionid
inner join mdl_grade_grades gg on gg.userid=u.id
INNER JOIN mdl_grade_items gi ON gi.'id' = gg.'itemid'
INNER JOIN mdl_quiz_slots qs ON qs.questionid=qa.questionid
Inner Join mdl_quiz quiz ON quiz.id=qs.quizid
inner join mdl_question_categories qc ON qc.id=q.category
where substring(u.department,2,1) = 4
and substr(gi.itemname,1)= 4
and substr(gi.itemname,-1)= 1
and substr(quiz.ano,1,4)=2018
and u.lastname=213
and substr(quiz.name,1)= 4
and substr(quiz.name,-1)= 1
AND itemtype = "mod"
AND itemmodule = "quiz"
AND finalgrade != "NULL"
and qas.state!="todo"
and qas.state!="complete"
and aggregationstatus = "used"
and SUBSTR(qc.name,8) = "MATEMATICA"
and qs.slot=qa.slot
group by turma, u.id
ORDER BY turma ASC, 'Aluno' ASC
I found the option
UNION ALL
but the results are shown one beneath the other, I would like you to create a column for each discipline