Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 998467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:11:57+00:00 2026-05-16T07:11:57+00:00

I have a table called user_logins which tracks user logins into the system. It

  • 0

I have a table called user_logins which tracks user logins into the system. It has three columns, login_id, user_id, and login_time

login_id(INT) | user_id(INT) | login_time(TIMESTAMP)
------------------------------------------------------
      1       |      4       |   2010-8-14 08:54:36
      1       |      9       |   2010-8-16 08:56:36
      1       |      9       |   2010-8-16 08:59:19
      1       |      3       |   2010-8-16 09:00:24
      1       |      1       |   2010-8-16 09:01:24

I am looking to write a query that will determine the number of unique logins for each day if that day has a login and only for the past 30 days from the current date. So for the output should look like this

 logins(INT) | login_date(DATE)
 ---------------------------
     1       |  2010-8-14
     3       |  2010-8-16

in the result table 2010-8-16 only has 3 because the user_id 9 logged in twice that day and him logging into the system only counts as 1 login for that day. I am only looking for unique logins for a particular day. Remember I only want the past 30 days so its like a snapshot of the last month of user logins for a system.

I have attempted to create the query with little success what I have so far is this,

SELECT
  DATE(login_time) as login_date,
  COUNT(login_time) as logins
FROM
  user_logins
WHERE
  login_time > (SELECT DATE(SUBDATE(NOW())-1)) FROM DUAL)
  AND
  login_time < LAST_DAY(NOW())
GROUP BY FLOOR(login_time/86400)

I know this is wrong and this returns all logins only starting from the beginning of the current month and doesn’t group them correctly. Some direction on how to do this would be greatly appreciated. Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T07:11:57+00:00Added an answer on May 16, 2026 at 7:11 am

    You need to use COUNT(DISTINCT ...):

    SELECT
        DATE(login_time) AS login_date,
        COUNT(DISTINCT login_id) AS logins
    FROM user_logins
    WHERE login_time > NOW() - interval 30 day
    GROUP BY DATE(login_time)
    

    I was a little unsure what you wanted for your WHERE clause because your question seems to contradict itself. You may need to modify the WHERE clause depending on what you want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.