查询分区并按要求分组

select a.*
from (select SCORE_ID,EX_EB_ID,EB_NAME,ss.ADMISSION_TICKET,SCOPE,EXAM_TIME,UPDATE_TIME,
ei.examinee_id,ei.examinee_name, ei.register_dept,ei.dept_code,ei.register_station, ei.station_code,
row_number() OVER(partition by dept_code, ei.station_code ORDER BY ss.scope desc) a_rownum
from TM_STUDENT_SCORE ss
left join tm_examinee_info ei on ss.admission_ticket =ei.admission_ticket) a
where a_rownum <= 3

这条SQL语句的作用:
计算出考生的成绩和考生资料,并按职务来分组,并得出该职务的前3名,

难理解的地方:
1.row_number() OVER(partition by dept_code, ei.station_code ORDER BY ss.scope desc) a_rownum
这句是按dept_code, ei.station_code分组,并按ss.scope 升序 最后命名为:a_rownum

你可能感兴趣的:(查询)