SELECT serial_std,SUM(sbj_tot) as total,SUM(sbj_num) as num_subjects,SUM(sbj_tot)/SUM(sbj_num) as d_average
	FROM
		((SELECT vag.serial_std, SUM(vag.act_grade) as sbj_tot, COUNT(vag.serial_sbc) as sbj_num
		FROM view_activity_grades vag
		WHERE serial_std=1 AND serial_prd=1 AND serial_att=1
		GROUP BY serial_std,serial_prd,serial_att)
		UNION
		(SELECT vog.serial_std, SUM(vog.act_grade) as sbj_tot, COUNT(vog.serial_osb) as sbj_num
		FROM view_opt_activity_grades vog
		WHERE serial_std=1 AND serial_prd=1 AND serial_att=1
		GROUP BY serial_std,serial_prd,serial_att))as period_grades
WHERE serial_std = 1