sql 排名情况
1. rank()、row_number()方法的使用:
rank () OVER ( partition BY m.pubno, m.ItemNo, m.taskno, m.org //在这些分组中实现各自rank()来实现排序,rank()改为row_number()时,不会因分数的相同而使排名相同。 ORDER BY m.score_total DESC )
2.case when then .. else .. end的使用,该语法还可以在查询字段时对一些条件进行判断来是否给值。例当分为0时不进行排名。
SUM ( //及格率的实现 CASE WHEN a.ExamScore > 60 THEN 1 ELSE 0 END ) / COUNT (*) * 100AS '及格率'
3.存储过程实现可选参数:可以先给参数赋予一个默认的值,然后在查询语句的where条件中写该参数的多个条件组合。
参数为@pubno WHERE ( @pubno = 'NULL' OR @pubno = '' OR a.pubno = @pubno ) AND ( @taskno = 'NULL' OR @taskno = '' OR a.taskno = @taskno )...........