Laravel foreach

为什么生成的查询语句不正确
SELECT
tr.temperature AS temperature,
count(*) AS count_temperature_all
FROMtemperature_record AS tr
LEFT JOIN school_student AS ss ON ss.id = tr.type_id
LEFT JOIN school_grade AS sg ON sg.id = ss.grade_id
LEFT JOIN school_student AS ss ON ss.id = tr.type_id
LEFT JOIN school_grade AS sg ON sg.id = ss.grade_id
WHERE
(tr.timestamp <= 2020 - 05 - 07 23 : 59 : 59
AND tr.timestamp >= 2020 - 04 - 23 00 : 00 : 00
)
AND tr.type = student
AND ss.grade_id = 2
AND tr.type = student
AND ss.grade_id = 3
GROUP BYtemperature
关于 LearnKu
(clone $query)->leftJoin(...)