Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query to compare signup date to FIRST purchase date

Status
Not open for further replies.

Louise99

Technical User
Sep 13, 2004
70
US
I have two tables. One has my customer name and ID with the date of their sign-up. The other has the customer ID with the dates of orders. I need to compare the databases to find out the what the time is between the sign-up and the FIRST order. One confusing factor: there may be more than one signup date because the "new signup" can expire. There aren't very many of those but there are some. Should I move the duplicates to a new table. Any advice?

Thanks!
 
how do you determine which records have "expired"? Do they get a new customer number if they sign up again?

Something like:

SELECT C.CustomerID, C.CustomerName, C.DateOfSignup, O.DateOfFirstOrder FROM Customer
INNER JOIN (SELECT CustomerID, MIN(OrderDate) As DateOfFirstOrder FROM Orders GROUP BY CustomerID) O ON C.CustomerID = O.CustomerID
WHERE C.ExpiredSignUp = False

Leslie

Anything worth doing is a lot more difficult than it's worth - Unknown Induhvidual

Essential reading for anyone working with databases:
The Fundamentals of Relational Database Design
Understanding SQL Joi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top