homepage Welcome to WebmasterWorld Guest from 54.146.190.193
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderator: open

Databases Forum

    
SQL to return counts of values
Joff

5+ Year Member



 
Msg#: 3396331 posted 10:52 pm on Jul 16, 2007 (gmt 0)

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)

 

phranque

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



 
Msg#: 3396331 posted 11:05 pm on Jul 16, 2007 (gmt 0)

SELECT COUNT(answercolumn), answercolumn FROM tablename GROUP BY answercolumn

Joff

5+ Year Member



 
Msg#: 3396331 posted 7:26 am on Jul 17, 2007 (gmt 0)

Fantastic, thanks!

phranque

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



 
Msg#: 3396331 posted 8:34 am on Jul 17, 2007 (gmt 0)

if it's a big enough table you might want an index on "answercolumn".

Joff

5+ Year Member



 
Msg#: 3396331 posted 9:25 pm on Jul 17, 2007 (gmt 0)

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!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved