I have the following query which has an issue with Query Builder.
SELECT Sum(TEMP.total) AS total_amount
FROM (SELECT Ifnull(t3.amount, t1.amount) AS total
FROM table1 AS t1
LEFT JOIN table2 AS t2
ON t2.class = t1.class
LEFT JOIN table3 AS t3
ON t3.student = t2.student
AND t3.type = t1.type) AS TEMP
Is there any way to do it with Query Builder? I'm currently using this method.