Page 1 of 1

how to query this ??

Posted: Mon Jun 18, 2007 12:55 am
by PHPycho
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

Posted: Mon Jun 18, 2007 12:57 am
by Benjamin

Code: Select all

SELECT COUNT(*) AS da_total FROM da_table WHERE da_field='x'

Posted: Mon Jun 18, 2007 1:43 am
by PHPycho
Pardon me
Cant we do without using where condition, ie what i want
Thanks again

Posted: Mon Jun 18, 2007 2:15 am
by Gente
If you don't like WHERE you can HAVING :)
But if we talking seriously what problems with WHERE?

Posted: Mon Jun 18, 2007 2:27 am
by John Cartwright
If you want to calculate the count for each respective value, you can use the GROUP BY clause