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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:22:04+00:00 2026-06-06T10:22:04+00:00

I was trying to find a solution but did not succeed even if it

  • 0

I was trying to find a solution but did not succeed even if it seems simple. So this might be a newbie question…

I have a table userscores with 3 columns:

date          userid   points
2012-05-01    1        23
2012-06-01    1        34
2012-07-01    1        44
2012-05-01    2        78
2012-06-01    2        94
2012-07-01    2        99
2012-06-01    3         2
2012-07-01    3         9

Now I need to get the difference of the points between 2012-05-01 and 2012-06-01 for each user.

Users’ points that are not existing (example userid 3) have to be calculated as 2 – 0… for this I guess I can use COALESCE(qa_points,0).

I read about combining two subqueries for the calculation but failed implementing it.

Any help appreciated.

PS: This is not working:

SELECT t1.userid, t1.points - t2.points AS mpoints FROM (
        SELECT userid,points FROM `userscores` 
        WHERE YEAR(date) = YEAR('2012-05-01') 
        AND MONTH(date) = MONTH('2012-05-01') ) 
        AS t1
    JOIN (
        SELECT userid,points FROM `userscores` 
        WHERE YEAR(date) = YEAR('2012-04-01') 
        AND MONTH(date) = MONTH('2012-04-01') ) 
        AS t2
    ORDER BY mpoints DESC, t1.userid DESC;
  • 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-06T10:22:06+00:00Added an answer on June 6, 2026 at 10:22 am

    I suppose your query will look like this:

        SELECT ul.userid, 
               ul.points - COALESCE(uf.points, 0) AS points_difference
          FROM userscores ul 
     LEFT JOIN 
               (SELECT userid, points FROM userscores WHERE `date` = '2012-05-01') AS uf
            ON uf.userid = ul.userid
         WHERE ul.date = '2012-06-01'
    

    LEFT JOIN is used because you told that there may be no records for this user/former date combination.

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

Sidebar

Related Questions

What I'm trying to do seems very simple, but I did not yet find
I have searched around Google and StackOverflow trying to find a solution to this,
Googled everything, but can't find solution for my problem. When i'm trying to deploy
I'm trying to find a simple solution to a specific problem, which is a
I'm trying to find the best solution: I have a usermodel and the user
Im having difficulties creating a query. I have googled a lot but did not
This is probably jquery basics, but I can't find a solution after much googling.
I have searched online and tried the below solution but it does not work;
I may not have enough information to generate a complete question here but I
I'm trying to find a solution to add HTTP digest auth to a site

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.