0

このクエリがあります

select movie_name, user_name
from movie natural join movie_queue natural join users
group by (movie_name, user_name)
order by movie_name;


これにより、以下のようなリストがドロップされます。

 MOVIE_NAME                                              USER_NAME              
------------------------------------------------------- ------------------------
E.T. the Extra-Terrestrial                              Cris                     
E.T. the Extra-Terrestrial                              Elizabeth                
E.T. the Extra-Terrestrial                              John                     
E.T. the Extra-Terrestrial                              Mary                     
E.T. the Extra-Terrestrial                              Peter                    
Indiana Jones and the Kingdom of the Crystal Skull      Elizabeth                
Indiana Jones and the Kingdom of the Crystal Skull      John                     
Indiana Jones and the Kingdom of the Crystal Skull      Mary                     
Jurassic Park                                           Elizabeth                
Jurassic Park                                           John                     
Jurassic Park                                           Mary                     
Jurassic Park                                           Peter                    
Signs                                                   Elizabeth                
The Sixth Sense                                         Mary                     
Unbreakable                                             John                     
Unbreakable                                             Mary                     
Unbreakable                                             Peter                    
War of the Worlds                                       Elizabeth                
War of the Worlds                                       John                     
War of the Worlds                                       Mary                     
War of the Worlds                                       Peter  


問題は、行の人気度と movie_name で並べ替えるにはどうすればよいですか?
現在、movie_name でリストを並べ替えていますが、最も人気のある映画から人気の低い映画の順に並べたいと考えています。


望ましい結果: 結果
として、"ET the Extra-Terrestrial" の行が最初に表示される必要があります。これは、テーブルに複数回表示されるためです。"The Sixth Sense" は、"Signs" の直後の最後に表示される必要があります。最後の映画は両方とも 1 回しか登場しないため、S は T の前に表示されます。

これを追加してみました: order by count(movie_name), movie_name;

しかし、私はまだ私が望む結果を得ることができません。最後にムービーはこのように整理する必要があります

これは私がそれらをどのように整理したいかです: 人気のあるものから人気のないものへ、アルファベット順に

 MOVIE_NAME                                              USER_NAME              
------------------------------------------------------- ------------------------
E.T. the Extra-Terrestrial                              Cris                     
E.T. the Extra-Terrestrial                              Elizabeth                
E.T. the Extra-Terrestrial                              John                     
E.T. the Extra-Terrestrial                              Mary                     
E.T. the Extra-Terrestrial                              Peter  
Jurassic Park                                           Elizabeth                
Jurassic Park                                           John                     
Jurassic Park                                           Mary                     
Jurassic Park                                           Peter 
War of the Worlds                                       Elizabeth                
War of the Worlds                                       John                     
War of the Worlds                                       Mary                     
War of the Worlds                                       Peter   
Indiana Jones and the Kingdom of the Crystal Skull      Elizabeth                
Indiana Jones and the Kingdom of the Crystal Skull      John                     
Indiana Jones and the Kingdom of the Crystal Skull      Mary  
Unbreakable                                             John                     
Unbreakable                                             Mary                     
Unbreakable                                             Peter 
Signs                                                   Elizabeth                
The Sixth Sense                                         Mary                 

前もって感謝します

4

2 に答える 2

0

order by 句には複数の列を指定できます。さらに、desc、asc を混在させることもできます。

あなたの場合、それは次のようになります:

select movie_name, user_name, count(movie_name) popularity 
from movie natural join movie_queue natural join users
group by (movie_name, user_name)
order by popularity, movie_name;

参照: http://psoug.org/reference/orderby.html

于 2012-07-22T06:04:04.410 に答える
0

次のようにしてみてください。

select movie_name, user_name
from movie natural join movie_queue natural join users
order by count(*) over (partition by movie_name) ,movie_name;
于 2012-07-22T08:29:12.163 に答える