0
此查詢對子查詢的處理速度很慢。我還沒有權限創建臨時表,但無論如何要進一步優化這個查詢,或者我在某處使用了破壞的邏輯嗎?查詢使用子查詢慢速運行
SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED ;
SELECT
CONCAT(u.firstname , ' ' , u.lastname) as Student_name,
u.id as Student_ID,
FROM_UNIXTIME(u.firstaccess) as first_moodle_access,
FROM_UNIXTIME(u.lastaccess) as last_moodle_access,
FROM_UNIXTIME(last.timeaccess) as last_course_access,
grp.name as Cohorts,
cour.fullname as course
FROM
mdl_user as u
Inner Join mdl_user_lastaccess as last on u.id = last.userid
Inner Join mdl_course as cour on last.courseid = cour.id
Inner Join mdl_groups as grp on cour.id = grp.courseid
WHERE u.lastlogin = (
Select Max(u2.lastlogin)
From mdl_user as u2
where u2.lastlogin = u.lastlogin
)
AND cour.id = '10189' AND
u.firstaccess > '0' AND
u.lastaccess > '0';
嘗試在您在哪裏條件下使用的所有字段上創建索引。子查詢中的'lastlogin','id','firstaccess','lastaccess' – jaym
您應該添加'AND u2.id = u.id'。這可能不是一個巨大的速度提升,但結果會更準確。 – CptMisery