CREATE VIEW v_course_ratings AS 
SELECT c.*, 
(SELECT CAST(AVG(score) AS UNSIGNED) FROM ratings WHERE course_id = c.id) AS total_score,
(SELECT COUNT(*) FROM ratings WHERE course_id = c.id) AS total_ratings  
FROM courses c 
WHERE c.status = 1;