Oracle排名函數(Rank)實例詳解建站知識
導讀:1建站知識這篇文章主要介紹了Oracle排名函數(Rank)實例詳解,需要的朋友可以參考下營銷型網站建設網站seo優化課程。
--已知:兩種排名方式(分區和不分區):使用和不使用partition
--兩種計算方式(連續,不連續),對應函數:dense_rank,rank
·查詢原始數據:學號,姓名,科目名,成績
select * from t_score
S_ID
S_NAME
SUB_NAME
SCORE
1
張三
語文
80.00
2
李四
數學
80.00
1
張三
數學
0.00
2
李四
語文
50.00
3
張三豐
語文
10.00
3
張三豐
數學
3
張三豐
體育
120.00
4
楊過
JAVA
90.00
5
mike
c++
80.00
3
張三豐
Oracle
0.00
4
楊過
Oracle
77.00
2
李四
Oracle
77.00
·查詢各學生科目為Oracle排名(簡單排名)
select sc.s_id,sc.s_name,sub_name,sc.score,
rank() over (order by score desc) 名次
from t_score sc
where sub_name='Oracle'
S_ID
S_NAME
SUB_NAME
SCORE
名次
4
楊過
Oracle
77.00
1
2
李四
Oracle
77.00
1
3
張三豐
Oracle
0.00
3
對比:rank()與dense_rank():非連續排名與連續排名(都是簡單排名)
select sc.s_id,sc.s_name,sub_name,sc.score,網站seo優化軟件
dense_rank() over (order by score desc) 名次
from t_score sc
where sub_name='Oracle'
S_ID
S_NAME
SUB_NAME
SCORE
名次
4
楊過
Oracle
77.00
1
2
李四
網站推廣優化seoOracle
77.00
1
3
張三豐
Oracle
0.00
2
·查詢各學生各科排名(分區排名)
select sc.s_id,sc.s_name,sub_name,sc.score,
rank() over
(partition by sub_name order by score desc) 名次
from t_score sc
S_ID
S_NAME
SUB_NAME
SCORE
名次
4
楊過
JAVA
90.00
1
4
楊過
Oracle
77.00
1
2
李四
聲明: 本文由我的SEOUC技術文章主頁發布于:2023-05-22 ,文章Oracle排名函數(Rank)實例詳解建站知識主要講述詳解,函數,Oracle排名函數(Rank)實例詳解建站知識網站建設源碼以及服務器配置搭建相關技術文章。轉載請保留鏈接: http://www.bifwcx.com/article/web_4828.html