Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Oracle11g 按名称和最流行的标题排序-Oracle_Oracle11g - Fatal编程技术网

Oracle11g 按名称和最流行的标题排序-Oracle

Oracle11g 按名称和最流行的标题排序-Oracle,oracle11g,Oracle11g,我有这个疑问 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 ----

我有这个疑问

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  

问题是如何按行人气和电影名称排序?
我目前正在按电影名称订购列表,但我也想从 从最受欢迎的电影到不太受欢迎的电影


所需结果:
因此, “外星人”行应该首先出现,因为它在桌子上出现的次数更多,“第六感”应该最后出现,就在“符号”之后。因为最后两部电影只出现1次,但S在T之前

我尝试添加以下内容: 按计数排序(电影名称),电影名称

但我还是没有得到我想要的结果。 最后,电影应该这样组织

这就是我希望它们的组织方式:从受欢迎到不受欢迎,并按字母顺序排列

 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                 

提前感谢

您可以为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;
另请参见:

像这样尝试:

select movie_name, user_name
from movie natural join movie_queue natural join users
order by count(*) over (partition by movie_name) ,movie_name;

@伯翰,谢谢!,我知道我可以有多个列,我尝试将count(movie_name)作为第二列,但仍然没有得到我想要的结果。我需要它把更受欢迎的电影放在第一位(受欢迎是基于有更多的行)。