Forum Moderators: open

Message Too Old, No Replies

Complicated query, need some help

         

dwalls32

4:40 pm on Mar 27, 2008 (gmt 0)

10+ Year Member



First of all, thank you to all who respond to this thread.

I am working on a little reporting app for work, and I am stuck on a query.

I have two tables, customers and events. The structure of those follows:

Customers
---------
CustomerId (key)
CreatedDTM
customername
accounttype (shows me whether or not they are a business)

Events
------
eventid (key)
customerid (to tie to the customers database)
created (date the event, like a call or email, was created)

I need to write a query that will show me all of the customers who have been created MORE than 30 days ago, are of the accounttype "1", and who have no events from the events table logged within the past 30 days as well

This is the most complicated query I have tried to write as of yet, and I am a little confused w/ the multiple statements that need to be made.

Thanks in advance for any help

LifeinAsia

5:13 pm on Mar 27, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Try soemthign like this (the exact implementation of creating the value for [30DaysAgo] will depend on your DB and/or programming language):
SELECT Customers.customername
FROM Customers
WHERE Customers.accounttype=1 AND Customers.CreatedDTM < '[30DaysAgo]' AND Customers.CustomerID NOT IN
(SELECT customerID FROM Events WHERE created > [30DaysAgo])

dwalls32

5:51 pm on Mar 27, 2008 (gmt 0)

10+ Year Member



I had no idea you could structure queries like that. It worked perfectly. Thank you, LifeinAsia!

old_expat

4:52 am on Apr 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



oops! sorry