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 payments before a specific date

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-20-07, 03:39
tsiger tsiger is offline
Registered User
 
Join Date: Sep 2007
Posts: 2
Find payments before a specific date

I need some help with a query i am trying to build. I have a table which holds annual member subscriptions. The table is like this

id | memberID | year | amount

and a typical select will return data like that:

1 | 001 | 1999 | 50
2 | 001 | 2000 | 50
3 | 001 | 2001 | 50
4 | 002 | 2000 | 50
5 | 002 | 2001 | 50
6 | 003 | 2000 | 50
7 | 003 | 2001 | 50

what i want to get is all the members who haven't paid after 2002.
Any ideas?
Reply With Quote
  #2 (permalink)  
Old 09-20-07, 04:11
aschk aschk is offline
Registered User
 
Join Date: Mar 2007
Location: 636f6d7075746572
Posts: 770
I think something like the following should work:
Code:
SELECT memberID,MAX(year) 
FROM <tablename> 
GROUP BY memberID HAVING MAX(year) < 2003

Edit : You don't need the MAX(year) in the select clause part of the statement.

Last edited by aschk; 09-20-07 at 04:23.
Reply With Quote
  #3 (permalink)  
Old 09-20-07, 04:33
tsiger tsiger is offline
Registered User
 
Join Date: Sep 2007
Posts: 2
yes this seems to work just fine thank you
Reply With Quote
Reply

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