Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
PHPycho
Forum Contributor
Posts: 336 Joined: Fri Jan 06, 2006 12:37 pm
Post
by PHPycho » Mon Jun 18, 2007 12:55 am
Hello forums !!
I would like to know how to count the no of fields that has specific values.
for example:
"table1" has field called "filed1" and it has values
------
|field1|
-------
|X |
|X |
|Y |
| X |
:
:
etc
I would like to know the no of rows that has the value X using count...
How to perform such query..
thanks in advance to all of you
Benjamin
Site Administrator
Posts: 6935 Joined: Sun May 19, 2002 10:24 pm
Post
by Benjamin » Mon Jun 18, 2007 12:57 am
Code: Select all
SELECT COUNT(*) AS da_total FROM da_table WHERE da_field='x'
PHPycho
Forum Contributor
Posts: 336 Joined: Fri Jan 06, 2006 12:37 pm
Post
by PHPycho » Mon Jun 18, 2007 1:43 am
Pardon me
Cant we do without using where condition, ie what i want
Thanks again
Gente
Forum Contributor
Posts: 252 Joined: Wed Jun 13, 2007 9:43 am
Location: Ukraine, Kharkov
Contact:
Post
by Gente » Mon Jun 18, 2007 2:15 am
If you don't like WHERE you can HAVING
But if we talking seriously what problems with WHERE?
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Mon Jun 18, 2007 2:27 am
If you want to calculate the count for each respective value, you can use the GROUP BY clause