1
I found the option UNION ALL but the results are shown one below of the other, I would like you to create a column for each discipline
I have these two queries and I would like to put them together, the difference between them is that one has a column called MediaMT
and the other MediaPT
, there is also a difference between the two in a Where line, where in one is SUBSTR(qc.name,8) = "MATEMATICA"
and the other is SUBSTR(qc.name,8) = "PORTUGUES"
I would like in the result that these two columns were shown one side by the other, it would be:
Mediapt | Mediamt | Mediageral ...
Follow the darlings:
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 below each other, I would like you to create a column for each discipline
In which of these tables is the column
fraction
?– Victor Stafusa
@Victorstafusa, that’s right, the column
fraction
is inqas
– Miguel Silva
I’ll test your answer, but I really appreciate the work you’ve done
– Miguel Silva