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 a skilled programmer specializing in Vue.js/Nuxt.js for front-end development and PHP Laravel for back-end solutions. I have a strong focus on API design and development, complemented by experience in web server setup and maintenance. My versatile expertise ensures seamless creation and maintenance of web applications, covering everything from intuitive user interfaces to robust server-side functionality. Passionate about coding and driven by a lifelong learning mindset, I invite you to explore more at danyal.dk.