If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Find if the person attended 4 times in any month

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-08-12, 17:58
xionhack xionhack is offline
Registered User
 
Join Date: Apr 2010
Posts: 7
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 18:02.
Reply With Quote
  #2 (permalink)  
Old 01-08-12, 18:25
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
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?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 01-08-12, 21:25
xionhack xionhack is offline
Registered User
 
Join Date: Apr 2010
Posts: 7
any member. Let's say when member_id = 4
Reply With Quote
  #4 (permalink)  
Old 01-08-12, 21:30
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Code:
SELECT EXTRACT(YEAR_MONTH FROM `date`) AS yyyymm
     , COUNT(*)
  FROM attendance
 WHERE member_id = 4
GROUP
    BY yyyymm
HAVING COUNT(*) >= 4
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 01-08-12, 21:31
xionhack xionhack is offline
Registered User
 
Join Date: Apr 2010
Posts: 7
Thank you very much! It works!
Reply With Quote
Reply

Tags
mysql

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On