tags:

views:

72

answers:

1

I have a mysql problem, my query looks as follows but not complete

SELECT
    s.name,
    s.surname
FROM
    students as s,
    practical as p,
    days_attend as d
WHERE
    s.sid = p.sid
AND
    s.sid = d.sid

The scenario is the user may enter in a form to search how many days the student has been absent, eg if he enters 5 it will bring up all students that have been absent for 5days. The problem however is every day the admin enters if the student is absent or not

eg.

TABLE: days_attend

id   sid  date        absent
1    1    2009-10-26  yes
2    1    2009-10-27  yes
3    1    2009-10-28  no
4    1    2009-10-29  yes
5    1    2009-10-30  yes
6    1    2009-10-31  no
7    1    2009-11-01  yes

I need to count the amount 5 rows where there are yes in column absent. he where count(absent) = 5?

+6  A: 

I think you are looking for the "having" clause:

Select count(*),sid
From days_attend
Where absent = 'yes'
Group By sid
Having count(*) = 5

MySQL Docs

brendan