Something
public text v1 · immutable$stmt = '
SELECT
`df`.`id`,
`df`.`full_name`,
`df`.`filesize`,
`df`.`hits`,
ROUND(SUM(`dr`.`rating`) / COUNT(`dr`.`id`), 2) AS `rating`
FROM
`downloads_files` AS `df`
LEFT JOIN
`downloads_ratings` AS `dr` ON `dr`.`file_id` = `df`.`id`
WHERE
' . $this->getCriterias() . '
GROUP BY
`df`.`id`
ORDER BY
`' . $sorting['by'] . '` ' . $sorting['type'] . ', `df`.`filename` ASC
LIMIT
' . ( int )$offset * $this->files_to_fetch . ', ' . $this->files_to_fetch;