初級SQL第三章 (sql的高階查詢)
阿新 • • 發佈:2018-12-09
- ——排序函式 over([分組子句] 排序語句[排序方式])
- ——row_number() 行號
- select row_number() over(order by score desc) as '排名',
- StuInfo.stuid,stuname,score from StuInfo,StuMarks
- where StuInfo.stuid=StuMarks.stuid and StuMarks.subject='java'
- ——rank() 存在並列時跳空
- select rank() over(order by score desc) as '排名',
- StuInfo.stuid,stuname,stusex,score from StuInfo,StuMarks
- where StuInfo.stuid=StuMarks.stuid and StuMarks.subject='java'
- ——dense_rank() 存在並列時不跳空
- select dense_rank() over(order by score desc) as '排名',
- StuInfo.stuid,stuname,stusex,score from StuInfo,StuMarks
- where StuInfo.stuid = StuMarks.stuid and StuMarks.subject='java'
- ——dense_rank() 存在並列時不跳空
- select dense_rank() over(order by sum(score) desc) as '排名',
- StuInfo.stuid,stuname,stusex,sum(score) '總分' from StuInfo,StuMarks
- where StuInfo.stuid = StuMarks.stuid
- group by StuInfo.stuid,stuname,stusex
- ——partition by 分組子句
- select dense_rank() over(partition by subject order by score desc)as '排名',
- StuInfo.stuid,stuname,subject,score from StuInfo,StuMarks
- where StuInfo.stuid=StuMarks.stuid