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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:35:21+00:00 2026-05-28T16:35:21+00:00

This is really a head scratcher for me. Essentially I have 3 MySQL tables

  • 0

This is really a head scratcher for me. Essentially I have 3 MySQL tables that collectively keep track of someone’s score (for a game let’s say). New scores can always be input. Essentially what I need to figure out is what players have improved their score from the past week (for this, they need to have a score before the week started AND after). Here is my table layout:

   USER                   REQUEST (ASSOCIATIVE TABLE)                   SCORE
+----------+    +-----------------------------------------+       +--------------------+
| id (int) |    | id  |    user_id   |    date (UNIX TS)  |       | request_id | score |
+----------+    +-----------------------------------------+       +--------------------+
|    3     |    |  1  |      3       |    before week     |       |     1      |  10   |
|    4     |    |  2  |      3       |    after week      |       |     2      |  20   |
|    5     |    |  3  |      4       |    before week     |       |     3      |  5    |
+----------+    |  4  |      5       |    after week      |       |     4      |  15   |
                +-----------------------------------------+       +--------------------+

So essentially, from those tables, I want to have user with ID of 3 to be returned because he’s the only one that has improved his score this last week.

So far, this is where I’ve come to but I really am having trouble moving forward:

SELECT user.id AS user_id, score, count(*) AS n 
FROM user 
LEFT JOIN request ON request.user_id = user.id 
LEFT JOIN score ON score.request_id = request.id WHERE request.date > (WEEK UNIX TS) 
GROUP BY user_id HAVING n > 1 
ORDER BY request.date DESC

Thanks for your help! 🙂

  • 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-28T16:35:22+00:00Added an answer on May 28, 2026 at 4:35 pm
    SELECT user.id             AS user_id
         , MAX(sc_now.score)   AS score_now
         , MAX(sc_prev.score)  AS score_previous
    
    FROM user 
    
      JOIN request AS req_now
        ON  req_now.user_id = user.id 
        AND req_now.date > (WEEK UNIX TS)    --- condition for this week 
      JOIN score AS sc_now
        ON sc_now.request_id = req_now.id 
    
      JOIN request AS req_prev
        ON  req_prev.user_id = user.id 
        AND req_prev.date BETWEEN ? AND ?    --- condition for previous week
      JOIN score AS sc_prev
        ON sc_prev.request_id = req_prev.id 
    
    GROUP BY user.id
    
    HAVING MAX(sc_now.score) > MAX(sc_prev.score)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This really, really urks me, so I hope that someone can give me a
Hello everyone, I have been banging my head really hard trying to solve this
So this really put headache on my head and I finally gave up and
I'm really banging my head off a wall now with this. I've installed PostgreSQL
I've been knocking my head against this for some time now. I'm not really
I've got this really simple piece of code that I thought was the correct
i have this really weired js problem. in summary, i get a element not
Has anyone noticed this behavior before? This really threw me off... I would have
I think this is really simple, but I can't get my head around it.
Hi I've googled for this...it's been 2 days...this null stuff really cracking my head!

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.