Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2010
    Posts
    8

    Unanswered: Find if the person attended 4 times in any month

    Hello. I am making a project on PHP i have 2 tables, a "member" table and an "attendance" table.

    On the "member" table I have the fields "member_id", "first_name", "last_name"
    On the "attendance" table I have "attendance_id", "date" , "member_id"

    What I want to find out is if the person has attended 4 times on "any month". Meaning, check if the person has attended 4 times without me having to specify the month and having to run a query against the month. But 4 times on any month, it cannot be 4 times in 2 months but 4 times in 1 month. Thanks!
    Last edited by xionhack; 01-08-12 at 19:02.

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by xionhack View Post
    What I want to find out is if the person has attended 4 times on "any month". Meaning, check if the person has attended 4 times without ...
    you want to do this for a specific person? which one?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Apr 2010
    Posts
    8
    any member. Let's say when member_id = 4

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    SELECT EXTRACT(YEAR_MONTH FROM `date`) AS yyyymm
         , COUNT(*)
      FROM attendance
     WHERE member_id = 4
    GROUP
        BY yyyymm
    HAVING COUNT(*) >= 4
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    Join Date
    Apr 2010
    Posts
    8
    Thank you very much! It works!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •