Hi Abu,
It would be very useful to point to where you found this query, so that one can perhaps update it for the benefit of everybody.
You didn't wrote which Moodle version you use, and which logging method?
mdl_log is the old (legacy) logging table, and Moodle 2.7 introduced mdl_logstore_standard_log as new (standard) logging table.
When using mdl_logstore_standard_log (replacing mdl_log), you must modify the query, to replace (only for this table) :
- mdl_log by mdl_logstore_standard_log
- course by
courseid
- time by timecreated
HTH,
Séverin