Welcome to WebmasterWorld Guest from 54.211.101.8

Forum Moderators: open

SQL to return counts of values

   
10:52 pm on Jul 16, 2007 (gmt 0)

5+ Year Member



I'm trying to accomplish this with one DB call if possible.

I've got a table with a "where did you hear about us" column, the contents are predetermined and are for example "google, friend, word of mouth, other".

Is there a way to return a count of this column and group the results by answer type?

Eg:
Google (245)
Friend (23)
Word of Mouth (83)
Other (34)

11:05 pm on Jul 16, 2007 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



SELECT COUNT(answercolumn), answercolumn FROM tablename GROUP BY answercolumn
7:26 am on Jul 17, 2007 (gmt 0)

5+ Year Member



Fantastic, thanks!
8:34 am on Jul 17, 2007 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



if it's a big enough table you might want an index on "answercolumn".
9:25 pm on Jul 17, 2007 (gmt 0)

5+ Year Member



It's only around 3000 rows at the moment, so not a huge table by any means.

I don't think this SQL's going to be called more than once a week so it's not going to put a strain on anything but I'd not even considered indexing that column so thanks again!

 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month