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 9089001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:02:12+00:00 2026-06-16T22:02:12+00:00

This is my first post on stackoverflow, although I’ve used it as a reference

  • 0

This is my first post on stackoverflow, although I’ve used it as a reference for a long time. So thanks for all the guidance you’ve provided me in the past. I really appreciate it. Here is my issue:

I have two tables, one called USERS and one called SIGNIN

USERS  
-----------------
userid | password

SIGNIN
--------------
suserid | date

I would like to count the number of times that a user has signed in over the period of the last week.

Here’s what I’ve got:

SELECT userid, password FROM USERS JOIN (SELECT suserid, COUNT(*) AS logins 
FROM signin 
WHERE WEEKOFYEAR(date) = WEEKOFYEAR(CURDATE()) && signin.suserid = users.userid) 
GROUP BY userid

I just can’t wrap my head around how to JOIN a subquery and make it count each individuals’ logins (date column) and return an individualized number for each individual. I know that query is totally jacked up but I’m just at that point, you know, where I’ve become so confused that I just need some guidance.

Any help and direction would be fantastic! I’ve read so many pages to no avail. Thanks, in advance!

** and thank you for the edits. They’ll help in the future when I post again.

  • 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-06-16T22:02:14+00:00Added an answer on June 16, 2026 at 10:02 pm

    Don’t try to do a subquery, just do the join and group by user id. Also, you want YEARWEEK so you are matching both the year and week, not just the week from any year.

    select userid, count(*)
        from users inner join signin on userid=suserid and yearweek(`date`) = yearweek(curdate())
        group by userid;
    

    left join instead of inner join if you want results of 0 for users who haven’t signed in.
    This follows what I assume is your intent of “last week” meaning the week of the current date (by default starting Sunday, but see the optional mode parameter to yearweek).

    Note that the users table here is completely optional; you could just do:

    select suserid, count(*) from signin
        where yearweek(`date`) = yearweek(curdate())
        group by suserid;
    

    but I’m guessing you may be getting other columns from user or wanting to exclude signins for deleted users.

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

Sidebar

Related Questions

this is my first post to stackoverflow, but I've used this amazing site before.
Hello stackoverflow guru's! This is my first post after having used the site for
Hello all! This is my first post on stackoverflow. After hours of searching and
First of all, this is my first post in stackoverflow. I use this side
This is my first post on StackOverflow. This community has provided me with some
This is my first post on stackoverflow, so please excuse me if my question
This is my first post in stackoverflow. I want to improve its google pagerank
this is my first post here on stackoverflow and am very impressed by the
This is my first post on stackoverflow so hopefully I don't sound too incompetent.
This is my first post to stackoverflow, so if this isn't the correct area

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.