MYSQL: Count of online users for last 90 days

Quick tip of the day, wounder you like to take a count of all active/online users from your databse for certain period of time. Following would be the query.

SELECT count(*) FROM users
WHERE active = 1 AND last_signin >= date_sub(now(), INTERVAL 90 DAY)
ORDER BY last_signin DESC;

In my case, I have two columns those I can target when make count of online active users.

  • active
  • last_signin

The query above will provide you count of active online users for last 90 days.

Author: Danyal
I'm working as programmer since 2002. Born, grew up, studied and worked in Pakistan now Im located in Denmark since 2006.