Forum Moderators: coopster

Message Too Old, No Replies

PhP MySQL COUNT()

Two count() statements in one query string

         

skipwater

10:25 pm on Feb 28, 2007 (gmt 0)

10+ Year Member



This is my first time posting here hope my request is not out of line.

I just can't seem to find any reference of a query string, using two count statements. Any help would be appreciated.

I need to count the records that have a good email and at the same time count the same records that have a bad email.

Then display that result in table form, Grouped by com,net,org etc.

I can get good or bad emails based on the query below but not both at the same time.

SELECT `reg_em_report` . `em_assoc` , '
. ' `reg_em_report` . `em_code` , '
. ' COUNT( * ) COUNT_E '
. ' FROM `reg_em_report` `reg_em_report` '
. ' WHERE `reg_em_report`.`email`!= ""'
. ' GROUP BY `reg_em_report` . `em_assoc` , '
. ' `reg_em_report` . `em_code`

This returns:

GROUP .......................... GOOD
COM Emails ..................... 123456
ORG Emails ..................... 1234

This is what I want returned:

GROUP .......................... GOOD ................ BAD
COM Emails ..................... 123456 .............. 1234
ORG Emails ..................... 1234 .............. 123

StupidScript

11:03 pm on Feb 28, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome aboard!

Sounds like 2 queries ... one where email isn't empty (GOOD) and one where it is (BAD). That's off the top of my head, but it's pretty low-intensity activity to make the queries.

A more-intensive activity would be to pull all records and get your count as the rows are iterated.

skipwater

1:30 am on Mar 1, 2007 (gmt 0)

10+ Year Member



Thanks for the reply:)

Yes my example of the query was presented very basic hoping that the question would be understood.

That might be the way I have to go;)
The reason that I did not want to do a while mysql_fetch_array routine was that I am dealing with a record count > 15 million. The server load is getting topped out.
I am trying to make one native mysql call to the table in hopes that the load would not create a problem.