views:

15

answers:

1

Can someone help me with a SQL Query that will display all users that have made a post every day for the last 7 days?

My questions table is tblQA and my users are userID and questionID for the post. I want to run a query that helps me know how many active users are using the database every day.

Thanks so much!

+1  A: 
SELECT userID
FROM tblQ
WHERE DATEDIFF(NOW(),postdate) < 7
GROUP BY userID
HAVING COUNT(DISTINCT DATE(postdate)) = 7
Wrikken
Thanks. This is only returning one user, but I know for sure there are at least 4-5 users posting everyday.
BigMike
Could you post some exact CREATE TABLE statements then? Works perfectly fine here (keep in mind _today_ is in the range, switch to `DATEDIFF(...) BETWEEN 1 AND 7` if you want it from yesterday to a week before that, your active users may yet have to post today.
Wrikken
This is my code: SELECT intPosterID FROM tblQA WHERE DATEDIFF(NOW(),dPostDateTime) < 7 GROUP BY intPosterID HAVING COUNT(DISTINCT DATE(dPostDateTime)) = 7
BigMike
And have all your active users already posted today?
Wrikken
The user that this query results in didn't even post today
BigMike
Ok, I think it actually is working, I messed up. Thanks for this.
BigMike