SELECT 
CONCAT(std.last_name_std,' ',std.first_name_std) as name_std,
CONCAT(sec.name_set,' ',lvl.name_lvl,' ',clg.name_clg) as curso,
cs.name_csb,
IF(sss.serial_sbg,'SI','NO') as calificado
FROM student std
JOIN student_by_course stc ON std.serial_std = stc.serial_std
JOIN course crs ON stc.serial_crs = crs.serial_crs
JOIN level_section_year lsy ON lsy.serial_lvl = crs.serial_lvl AND lsy.serial_set = crs.serial_set AND lsy.serial_scy = crs.serial_scy
JOIN level lvl ON crs.serial_lvl = lvl.serial_lvl
JOIN section sec ON sec.serial_set = crs.serial_set
JOIN class_group clg ON clg.serial_clg = crs.serial_clg

JOIN subject_course sc ON sc.serial_crs = crs.serial_crs AND sc.status_sbc = 'ACTIVE'
JOIN subject sbj ON sbj.serial_sbj = sc.serial_sbj AND sbj.status_sbj ='ACTIVE'
JOIN cat_subject cs ON cs.serial_csb = sbj.serial_csb AND cs.status_csb ='ACTIVE'

JOIN  year_subject_skills ys On ys.serial_sbc = sc.serial_sbc AND ys.status_yss ='ACTIVE' 
LEFT JOIN student_subperiod_subject_skill_grade sss ON sss.serial_yss = ys.serial_yss AND sss.status_sbg = 'ACTIVE' AND sss.serial_std = std.serial_std AND sss.serial_sbp =1

WHERE crs.serial_scy = 1
AND stc.status_stc = 'ACTIVE'
AND std.status_std = 'ACTIVE'


GROUP BY ys.serial_sbc

ORDER BY crs.serial_crs , std.serial_std,sss.serial_sbg