NYCPHP Meetup

NYPHP.org

[nycphp-talk] MySQL count( * ) syntax question

Mitch Pirtle mitchy at spacemonkeylabs.com
Mon Feb 9 19:09:11 EST 2004


Christopher R. Merlo wrote:

> On 2004-02-09 18:48 -0500, Tim Gales <tgales at tgaconnect.com> wrote:
> 
> 
>>You might try adding a 'sentinel' record.
> 
> 
> Well, the table where the zero counts should occur is a table of
> students' attendance records.  Each row has a date, student ID, and in
> column "attended", a value of 1, 2, or 3.  1 = present, 2 = absent, 3
> = excused.
> 
> The query basically looks like this:
> select id, first, last, etc., count( attended )
> from login, attendance
> where id = student /* where login.id = attendance.student */
> and attended = 2
> group by...
> 
> Basically, I want to select every student, and the amount of times
> he/she was absent (including never).  But I only get the students who
> were absent at least once.  I can't think of another way to get that,
> other than what feels like it would be a severe kludge.

Would that kludge include the use of mysql_num_rows?  You could just add 
that to your processing, or perhaps play about with SUM() and GROUP BY...



More information about the talk mailing list