需要SQL查询的帮助

时间:2011-05-08 16:56:32

标签: sql oracle

以下是相关表格:

movie 
(
    mvnumb int, 
    mvtitle char(100), 
    yrmde int, 
    mvtype char(9), 
    crit int, 
    mpaa char(6), 
    noms int, 
    awrd int, 
    dirnumb int
)


director 
( 
    dirnumb int, 
    dirname char(36), 
    dirborn int, 
    dirdied int
)

我的目标是构建一个SQL查询,列出已获得最大奖励数(awrd)的导演的姓名。我似乎无法让这个工作......任何帮助都会非常感激...非常感谢。

1 个答案:

答案 0 :(得分:3)

像这样的东西(SQL Server):

select top 1 d.dirname,sum(awrd) awrd
from director d
inner join movie m
on m.dirnumb=d.dirnumb
group by d.dirname
order by sum(awrd) desc

或者,在Oracle上:

select * from (
select d.dirname, sum(awrd) awards
from director d
inner join movie m
on m.dirnumb=d.dirnumb
group by d.dirname
order by sum(awrd) desc )
where rownum<2;

编辑:修改了Oracle查询,正如@pilcrow建议的那样。