homepage Welcome to WebmasterWorld Guest from 174.129.80.166
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Accredited PayPal World Seller

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderators: physics

Databases Forum

    
SQL to return counts of values
Joff




msg:3396333
 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




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

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

Joff




msg:3396714
 7:26 am on Jul 17, 2007 (gmt 0)

Fantastic, thanks!

phranque




msg:3396763
 8:34 am on Jul 17, 2007 (gmt 0)

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

Joff




msg:3397477
 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.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved