Re: Tally up a field in a database...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



If u only have 2 values 0 and 1 in ur column, then do the following to count all 1's

select sum("field_name") from "table_name"

else if u would generically like to count the number of records having a particular value, then do the following. Also do the following if u want to count all 0's

select count("field_name") from "table_name" where "field_name"="value"
or
select count(*) from "table_name" where "field_name"="value"




At 10:39 AM 5/9/03 +0100, Tristan.Pretty@risk.sungard.com wrote:
I have a field in a DB that has either 0 or 1 as the value.
It's part of a survey I'm doing.

I want to be able to take that field and tally up all the results, giving
a total for the user to see.
I know it's simple, but the friday bug has gripped me...

so if 30 users did the survey, and 12 selected 1, I want the result to
show '12'

Any ideas?

***********************************************************************
The information contained in this e-mail message is intended only for
the personal and confidential use of the recipient(s) named above.
If the reader of this message is not the intended recipient or an agent
responsible for delivering it to the intended recipient, you are hereby
notified that you have received this document in error and that any
review, dissemination, distribution, or copying of this message is
strictly prohibited. If you have received this communication in error,
please notify us immediately by e-mail, and delete the original message.
************************************************************************

Regards. Haresh D.Motwani. Systems Engineer, The Argon Company, 'Dhanraj Mahal' G - Block 4th floor, Apollo Bunder, Bombay 400039. INDIA

Tel: 91-22-5636 1313
Fax: 91-22-5636 1316

http://www.theargoncompany.com
http://syzigy.theargoncompany.com
http://www.w-o-i.com

[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux