开发者

SQL Sub query doubt

i'm a bit stuck and would appreciate the help..... i'm sure i need to use a sub query but when i try i m getting errors saying returning more than one row....

So this is the code

SELECT to_char(p.releasedate, 'YYYY') AS releaseyear , t.genre
, COUNT(*) AS "Number of awards"
FROM dbf11.film p
JOIN dbf11.genre t开发者_JS百科
ON p.filmID = t.filmID
GROUP BY p.releasedate, t.genre
ORDER BY p.releasedate, t.genre ;

What i'm trying to do is.... for each year display the no. of films for each genre

What i'm currently getting is

2010 Action 1
2010 Comedy 1
2010 Comedy 1
2011 Action 1
2011 Action 1
2011 Action 1

What i want it to display is

2010 Action 1
2010 Comedy 2
2011 Action 3


SELECT to_char(p.releasedate, 'YYYY') AS releaseyear, 
    t.genre.
    COUNT(*) AS "Number of awards"
FROM dbf11.film p
INNER JOIN dbf11.genre t ON p.filmID = t.filmID
GROUP BY to_char(p.releasedate, 'YYYY'), t.genre
HAVING COUNT(*) > 1
ORDER BY to_char(p.releasedate, 'YYYY'), t.genre;


Try this

SELECT to_char(p.releasedate, 'YYYY') AS releaseyear , t.genre
, COUNT(*) AS "Number of awards"
FROM dbf11.film p
JOIN dbf11.genre t
ON p.filmID = t.filmID
GROUP BY to_char(p.releasedate, 'YYYY'), t.genre
ORDER BY releaseyear, t.genre 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜