Count files by type (SQL query)

Count files by type (SQL query)

by Mikhail Apakin -
Number of replies: 0

Hi! Can't resolve a simple task. I need to make SQL-query to have a list of courses with number of files of some type (e.g. 'ppt').

I went in two ways:

SELECT cou.id, cou.fullname, count(f.id) FROM prefix_files f
LEFT JOIN prefix_context con ON f.contextid=con.id
LEFT JOIN prefix_course_modules mod ON mod.id=con.instanceid
LEFT JOIN prefix_course cou ON mod.course=cou.id
WHERE f.filename LIKE '%ppt%'
GROUP BY cou.id


and

SELECT c.id "CourseID",
CONCAT('', c.fullname ,'') AS "Course Name",
COUNT(
SELECT f.id FROM prefix_files AS f
LEFT JOIN prefix_context con ON f.contextid=con.id
LEFT JOIN prefix_course_modules mod ON con.instanceid=mod.id
LEFT JOIN prefix_course cou ON mod.course=cou.id
WHERE f.filename LIKE '%ppt%'
) "PPT Files"
GROUP BY c.id

Both of them have some error I can't catch. I feel that my mistake is stupid and simple, but can't find it. Help! Thank you.
Average of ratings: -