So I need to pull the e-mail addresses of members who have not logged into my site in the past 30 days.
Since the site is over a few years old, we want to pull only a handful of each member from certain Quarters of the year.
So for instance, there are about 800,000 people who haven't logged in within the past 30 days.
So we want to pull 300,000 users from that list, but we want to split it the sample over three years. Three years has twelve quarters. 300,000 /12 = 25,000.
So I want to pull 25,000 from Q1 2007
25,000 from Q2 2007
25,000 from Q3 2007
25,000 from Q4 2007
25,000 from Q1 2008
etc....
Would I need to write queries for each 'quertar" then union them or is there a way to do thsi all within one query?
SELECT Email, lastlogindate
FROM Users
WHERE DATEDIFF(dd, LastLoginDate, GetDate()) > 30
That's the basic query I have to pull all the data.
I basically want to avoid having to write 12 queries with where clauses like:
DATEPART(q, LastLoginDate) = 1 AND
DATEPART(yyyy, LastLoginDate) = 2007
any help would be greatly appreciated.