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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:31:31+00:00 2026-06-17T02:31:31+00:00

I have table structure like this: Id Name Rank Date ———————————– 1 test 1000

  • 0

I have table structure like this:

Id    Name      Rank      Date
-----------------------------------
1     test      1000      2012-1-11

2     test      7000      2012-1-10

3     test2     2000      2012-1-11

4     test2     200       2012-1-10

5     test3     4000      2012-1-10

6     test4     6500      2012-1-11

Consider today date is 2012-1-11
Yesterday date is 2012-1-10

In single query i get the difference between the each user name for today and yesterday’s date.
i.e test has 7000 rank on yesterday and 1000 on today. So the result is 6000
Similarly test2 has -1800.

I need the output as:

Name     Difference (Orderby the difference Desc)
--------------------
test      6000
test2     -1800

If the today date or yesterday date’s record is not available then we will not take this record to calculation.

Is this possible in PHP MySQL?

  • 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-17T02:31:33+00:00Added an answer on June 17, 2026 at 2:31 am

    How about this? (not very clear what you are trying to achieve though..) Pleaes comment.

    • SQLFIDDLE DEMO

    Code:

    select b.id, b.name, (b.rank-a.rank) diff
    from t1 a
    left join t1 b
    on b.date < a.date
    and b.name = a.name
    having not diff is null
    ;
    

    Results:

    ID  NAME    DIFF
    2   test    6000
    4   test2   -1800
    

    Edit as per OP’s comment:

    Notice that I have added extra few records to your sample table for triggering out conditions.

    • SQLFIDDLE DEMO2

    Code2:

    select b.id, b.name,b.rank AS New,
    b.Date new_date,
    a.Rank as Old, a.date as old_date, 
    (b.rank-a.rank) diff
    from t1 a
    left join t1 b
    on b.name = a.name
    where b.date > a.date and b.date <= Now()
    and datediff(b.date, a.date) = 1
    having not diff is null and diff <> 0
    order by diff desc
    ;
    

    Results:

    ID  NAME    NEW     NEW_DATE            OLD     OLD_DATE            DIFF
    3   test    8000    January, 12 2012    1000    January, 11 2012    7000
    4   test2   2000    January, 11 2012    200     January, 10 2012    1800
    1   test    1000    January, 11 2012    7000    January, 10 2012    -6000
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table structure with columns like this [ID] [Name] [ParentId] [ParentName] The
I have an table structure like this mysql> SELECT id, name, parent_id FROM categories;
I have a table structure something like this table Collection Id Name table Product
Hi i have a table structure like this. table **geoinfo** id name desc I
I have inherited a table with a structure something like this: ID Name Timestamp
I have a MySQL table structured somewhat like this: type name value ===================== 1
I have a table structure like this: <table> <tr> <td> <ul> <li class=check></li> </ul>
I have my Table structure like this :: ATT_Table : Fields - Act_ID, Assigned_To_ID,
If I have a table structure like this: Transaction [TransID, ...] Document [DocID, TransID,
My table have data structure like this cate_id task_id date_start date_end other 34 14

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.