2017-04-02 192 views
0

我有一張表格,裏面包含該縣所有學校的測試統計數據。我試着去顯示前10排名的學校,其中寫作和閱讀成績之間的差異是最大的排名前10位,但按字母順序排序,然後按排名。 SQL

select * 
    from 
     (select SchoolName, WriPassingPer, ReaPassingPer, 
     (WriPassingPer - WriPassingPer) as Difference, dense_rank() over 
       (order by ABS(WriPassingPer - WriPassingPer) desc) as rnk from Pima) 
    where rnk <= 10; 

我希望它看起來像

Rank | School Name | Writing Score | Reading Score | Difference 

但此刻它剛上市時每一個在縣的學校有1或2的等級。全縣有283所學校

回答

2

你計算WriPassingPer - WriPassingPer而不是WriPassingPer - ReaPassingPer或類似的東西...

+0

Omg。謝謝。我很慚愧 –

+1

好吧,不要,我們都去過那裏了(我們有些人還時不時!) –

+0

跟進問題。如何忽略WriPassingPer和ReaPassingPer的所有空值? –