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 skilled programmer with expertise in Vue.js/Nux.js for front-end development and PHP Laravel for back-end development. I excel in building APIs and services, and also have experience in web server setup & maintenance. My versatile skill set allows you to develop and maintain web applications effectively, from the user interface to the server-side functionality. I love coding with never ending learning attitude, thanks for visiting danya.dk