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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:23:17+00:00 2026-05-28T03:23:17+00:00

I have a table that stores values each hour from a website based on

  • 0

I have a table that stores values each hour from a website based on 100 users. Each user is there each hour, but might have a higher/lower value.

I want to find the highest difference between the rows and output them.

mysql_query("SELECT `username`,`energy` FROM `hoflevel`");

I know I could loop through all the rows of each user and find the highest value, but that is too much code. I’m sure there is a way to figure out the biggest difference between two rows, grouped by the username. It doesn’t have to be only each hour. It would be like a “Alan set the record of 345,048 Energy at 5am yesterday!“.

  • 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-28T03:23:18+00:00Added an answer on May 28, 2026 at 3:23 am

    This gets the maximum difference in energy per user, ignoring users with only a single record:

    SELECT hoflevel.username, MAX(hoflevel.energy-h.energy) as maxDiff 
    FROM hoflevel 
    LEFT JOIN hoflevel h 
    ON h.username=hoflevel.username AND hoflevel.energy>=h.energy
    WHERE h.energy IS NOT NULL
    GROUP BY hoflevel.username;
    

    Basically, it joins hoflevel to itself on username which produces a table with username and every pair of energy values for that user.

    Then it works out the maximum difference between energies grouped by username.

    Note, you could further save some computation by ignoring users who may have multiple records in the database but the same energy each time (and so their maxDiff is 0) by changing the >= to a > in the join condition.

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

Sidebar

Related Questions

I currently have a table in MySQL that stores values normally, but I want
I have voting system on my website, it stores each users vote in table
I have a stored procedure that returns values from a temp table. In my
I have a table that stores all the volunteers, and each volunteer will be
I have a table that stores user information. The table has a userid (identity)
I have a table User that stores user information - such as name, date
I have a mysql table that stores a mapping from an ID to a
I have a table in SQL Server 2008 that stores date/time values as varchar(max)
I have one table that stores values with a point in time: CREATE TABLE
I have a table that stores all values..eg x1, x2, x3 which determines fuzzy

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.