日期:2014-05-17 浏览次数:20717 次
-- 不考虑并列排名的话
SELECT ROW_Number() OVER(ORDER BY s.总分) AS 名次, s.单位id, s.单位名称, s.总分
FROM (SELECT t3.单位id, t3.单位名称, SUM(t2.信息得分) AS 总分
FROM tb3 INNER JOIN tb1 t1 ON t3.单位id=t1.信息录入单位id
INNER JOIN tb2 t2 ON t1.信息id = t2.信息id
WHERE Year(t1.录入时间) = 2013
GROUP BY t3.单位id, t3.单位名称 ) s
ORDER BY s.总分
-- 考虑并列排名
SELECT RANK() OVER(ORDER BY s.总分) AS 名次, s.单位id, s.单位名称, s.总分
FROM (SELECT t3.单位id, t3.单位名称, SUM(t2.信息得分) AS 总分
FROM tb3 INNER JOIN tb1 t1 ON t3.单位id=t1.信息录入单位id
INNER JOIN tb2 t2 ON t1.信息id = t2.信息id
WHERE Year(t1.录入时间) = 2013
GROUP BY t3.单位id, t3.单位名称 ) s
ORDER BY s.总分
select dense_rank() over(order by sum(t2.信息得分) desc) '名次',
t3.单位id,
t3.单位名称,
sum(t2.信息得分) '得分'
from tb1 t1
inner join tb2 t2 on t1.信息id=t2.信息id
inner join tb3 t3 on t1.信息录入单位id=t3.单位id
where year(t1.录入时间)=2013 and t2.审核类别=1
group by t3.单位id,t3.单位名称