Search code examples
mysql

7 Day Users Stat SQL Query


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!


Solution

  • SELECT userID
    FROM tblQ
    WHERE DATEDIFF(NOW(),postdate) < 7
    GROUP BY userID
    HAVING COUNT(DISTINCT DATE(postdate)) = 7