2015-10-20 108 views
0

Sample outputSQL排名功能

我想排名的安打率和總體在2013年,但不知道的功能:

Select playerID, yearID, Batting_average, teamID, lgID 

RANK() OVER (ORDER BY Batting_average DESC) AS BattingAverageRank 

From Material_Batting 

where yearID = 2013 

order by Batting_average; 

試過RANK () OVER ([ partition_by_clause ] order_by_clause)但沒有工作

+1

你試過的查詢是什麼?什麼都行不通,有什麼錯誤?什麼是預期的輸出? – Abhishek

+0

你能告訴我們一個期望的輸出樣本嗎?另外,當你嘗試時,你會得到什麼輸出? – Ahmad

+0

RANK()OVER(ORDER BY Batting_average DESC)AS BattingAverageRank 試過這個,但得到了錯誤:'''附近的錯誤語法。 – LebronJames

回答

0

試試這個:

SELECT playerID 
    ,yearID 
    ,Batting_average 
    ,franchName 
    ,rank() OVER (ORDER BY batting_average DESC) Batting_average_rank 
FROM Material_Batting 
WHERE yearID = 2013 
ORDER BY Batting_average 
+0

謝謝! – LebronJames