-- fact_teacher

select
	tp.org_id, 
	tp.person_id, 
	tp.person_name, 
	tp.xb_name, 
	tp.subject_id, 
	tp.subject_name, 
	tp.stage_id, 
	tp.stage_name, 
	tp.birthday, 
	tp.professional_title as professional_titlename, 
	tp.highest_degree, 
	case
            when (tc."class_id" is null) then 0
            else 1
        end as is_bzr
from
	(
		t_base_person as tp
		left join
		t_base_class as tc
		on 
			(
				(
					(
						tp.person_id = tc."bzr_id"
					) and
					(
						tc."b_use" = 1
					) and
					(
						tp.org_id = tc."org_id"
					)
				)
			)
	)
where
	(
		(
			tp.b_use = 1
		) and
		(
			tp.identity_id = 5
		)
	)
	
	-- v_hongqiban
	
	 SELECT e.school_id,
    "left"(e.class_name::text, 5) AS grade_name,
    e.class_name,
    sum(e.real_convert_score) AS score
   FROM t_intellioa_evaluate_daily_score_calc e
     JOIN t_intellioa_evaluate_daily_gather g ON e.gather_id = g.id AND g.is_deleted = 0
  WHERE e.evaluate_target = 1 AND e.is_deleted = 0 AND e.group_level = 10 AND g.system_type = 3
  GROUP BY e.school_id, e.task_id, e.task_name, e.plan_id, e.plan_name, e.class_id, e.class_name, g.create_year, g.class_num, e.class_teacher_id, e.class_teacher_name, g.gather_name
  ORDER BY (sum(e.real_convert_score)) DESC