Hi Aaron,

Aaron Clausen wrote:
I have a couple of very simple tables to handle a client signin site:

The client table has the following fields:
 client_id int(11) primary key auto_increment
 first_name char(90)
 last_name char(90)

The signin table has the following fields
 record_id int primary key auto_increment
 client_id int
 date datetime

Essentially, the client enters his id and it creates a record in the
signin table.

I need a query that can identify all the clients who signed in for the
first time during a specific month.  I have fought this one for a
couple of days now and just can't seem to get it.

I think you can break the problem into a couple of steps:

1) find the first login for each client.
2) eliminate all but the ones in the month.

You can't do step 2 first because that would destroy your knowledge of whether a signin record is a client's first.

   select client_id, min(date) from signin group by client_id;

Now you know the first time each client signed in. From here you can go several ways. One is to just add a HAVING clause.

   select client_id, min(date) from signin
   group by client_id
   having min(date) between ? and ?;

I hope that helps,
Baron

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to