2015-01-07 94 views
-1

我使用Microsoft Access作为后端。这是我做了ERD:访问SQL SUM和COUNT

enter image description here

这些都是表我:

VERTONING:

enter image description here

电影:

enter image description here

这是我做出的SQL:

SELECT titel 
    ,COUNT(vertoning) AS [aantal vertoningen] 
    ,SUM(aantaldagen) AS [aantal dagen] 
FROM film,vertoning 
WHERE vertoning = "bioscoop" 
GROUP BY titel; 

但是,如果我运行查询,我得到这个:

http://puu.sh/ebWAh/8f9a1346b6.png

虽然我应该得到这样的:

enter image description here

看起来像它而不是显示每个“电影代码”有多少“bioscoop”

如果有什么不明确的话,我会尽力解释它。

(我可以只发布2个链接在第一个3个环节的空间很抱歉)

+1

唐你需要一个连接条件吗? (将AND film.filmcode = vertoning.filmcode添加到您的WHERE子句中。) – jarlh

+0

是的,我需要为此使用连接条件。 我用你的线我的条款和结果就像我想要的一样! 非常感谢! – Shiyu

回答

0

考虑使用INNER JOIN:

SELECT Film.Titel, 
     COUNT(Vertoning.vertoning) AS [aantal vertoningen], 
     SUM(Vertoning.aantaldagen) AS [aantal dagen] 
FROM Film INNER JOIN Vertoning ON Film.FilmCode = Vertoning.Filmcode 
WHERE Vertoning.vertoning = "bioscoop" 
GROUP BY Film.titel; 

让我知道,如果它还是不能

+0

这似乎工作得太像加入jarlh建议我那样做。谢谢! – Shiyu