Work SQL: Requires that the average number of awards cannot be displayed by ranking

Working SQL:

need:

The average number of awards for teaching and research by teachers in the same department The average number of awards for teaching and research by teachers with the same professional title The average number of awards for teaching and research by teachers in the whole school

It is required that the average number of awards cannot be displayed by ranking

-- 教研获奖打败本部门教师人数 改为:部门排名 :5/145		
		select 
		RANK() OVER(partition by  a.xymc ORDER BY JYHJCS desc) || '/' || b.num JSRS,
		a.jzgh,
		a.JYHJCS,
		a.xymc
		from 
		(
			select 
			a.jzgh,
			a.xymc,
			sum(a.num)  JYHJCS
			from 
			(
			-- 	huojiang名单
			select 
			count(distinct a.CGMC) num,
			b.jzgh,
			b.xymc
			from 
			DC.jsx b
			join 
			MODEL.hjmd a 
			on a.ZYWCR=b.jzgxm
			where b.GWLX='专任教师'
			group by b.jzgh,b.xymc			
			union all			
			--成果奖
			select   
			count(distinct a.CGMC) num,
			b.jzgh,
			b.xymc
			from 
			DC.JSXXB b
			join 
			MODEL.JXCGJ a 
			on a.HJZ=b.jzgxm
			where b.GWLX='专任教师'
			group by b.jzgh,b.xymc
			) a 
			group by a.jzgh,a.xymc
		) a

analyze

Observation shows that the original SQL / right is the total number of people in this department, and you only need to accumulate all the number of winners in this department.

Modified SQL

select SUM(JYHJCS)  nums,xymc from (
   select 
   a.jzgh,
   a.xymc,
   sum(a.num)  JYHJCS
   from 
   (
   --  获奖名单
   select 
   DECODE(count(distinct a.CGMC), null, 0,count(distinct a.CGMC)) num,
   b.jzgh,
   b.xymc
   from 
   DC.JSXXB b
   left join 
   MODEL.HJMD a 
   on a.ZYWCR=b.jzgxm
   where b.GWLX='专任教师'
   group by b.jzgh,b.xymc  

expand

How to modify the teachers with the same professional title??

Guess you like

Origin blog.csdn.net/qq_58432443/article/details/125747668