Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to count rows?

Author  Topic 

jgonzalez14
Yak Posting Veteran

73 Posts

Posted - 2008-11-23 : 14:05:57
I am trying to find out how many movies have been rated. This seems to do it but i just need a count and do not need any of these selections. The m.title column gives me a distinct list of the movies that have been rated. I need this count which is 58 rows. How can I do this so that my result is just this: Count of movies: 58.

select  distinct  avg(r.rating), m.title, count(m.title) as countofMovies
from ratings r
inner join movies m
on m.movieid = r.movieid
group by m.title


Any ideas?

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-11-23 : 15:16:52
quote:
Originally posted by jgonzalez14

I am trying to find out how many movies have been rated. This seems to do it but i just need a count and do not need any of these selections. The m.title column gives me a distinct list of the movies that have been rated. I need this count which is 58 rows. How can I do this so that my result is just this: Count of movies: 58.

select count(distinct m.title) as countofMovies
from ratings r
inner join movies m
on m.movieid = r.movieid


Any ideas?

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-11-23 : 17:10:29
SELECT COUNT(DISTINCT movieid)
FROM Ratings



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page
   

- Advertisement -