SQL问题,请协助

时间:2015-03-29 06:32:32

标签: sql database ms-access

我想知道如何在SQL中列出这一点 - "哪些导演指导了不止一部电影,这部电影被提名为超过2个奥斯卡奖。奥斯卡颁奖典礼下令结果"。

我目前有这个......我知道这是不正确的。

SELECT DIRECTOR.dirID, MOVIE.mvTitle
FROM DIRECTOR
INNER JOIN
MOVIE ON DIRECTOR.dirID=MOVIE.dirID
ORDER BY noms>=2 DESC;

3 个答案:

答案 0 :(得分:0)

您没有添加where子句来检查条件,查询将是:

SELECT director.dirID, movie.mvTiltle 
FROM director 
INNER JOIN movie ON director.dirID = movie.dirID 
WHERE director.numOfMovies > 1 
    and movie.nom >= 2 
ORDER BY noms DESC

答案 1 :(得分:0)

您需要使用WHERE子句

SELECT DIRECTOR.dirID, MOVIE.mvTitle
FROM DIRECTOR
INNER JOIN MOVIE ON DIRECTOR.dirID = MOVIE.dirID
WHERE DIRECTOR.dirID > 1
AND MOVIE.noms > 2

答案 2 :(得分:0)

;with cte as (select d.dirid
    from movie m
    inner join director d on m.dirid=d.dirid
    where noms >1
    group by d.dirid
    having count(*)>1)
select cte.dirid,m.name,nos from cte 
inner join movie m on cte.dirid=m.dirid
order by noms desc;

这样的事情应该有效。这是小提琴: http://sqlfiddle.com/#!6/9db91/1