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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:56:07+00:00 2026-05-24T07:56:07+00:00

I have a table that looks like id Type: Auto inc-int Comment: the unique

  • 0

I have a table that looks like

id
Type: Auto inc-int
Comment: the unique id
Value Inserted auto inc int

dateGained
Type: dateTime
Comment: Date currency was gained
Value inserted: Current Date/Time

amntGained
Type: float
Comment: Amount of currency gained
Value inserted: value gained (e.g. 0.25)

amntUsed
Type: float
Comment: When part of the value is used this column gets updated
Value inserted: 0

uuid
Type: uuid
Comment: The users uuid
Value inserted: (a uuid)

so a few example rows (for a single user) would be

1 | 2010-07-30 00:00:00 | 0.25 | 0.20 | [uuid]  
2 | 2010-08-12 00:00:00 | 1.75 | 0.00 | [uuid]  
3 | 2010-08-17 00:00:00 | 8.25 | 0.00 | [uuid]  
4 | 2010-09-15 00:00:00 | 0.05 | 0.00 | [uuid]  

Now my question is around the logic:

Basically I have a function that is given a uuid and an amount, the function then has to go through starting from the oldest and update the used value untill the amount given is satisfied.

e.g. if the function was given 6.25 and [uuid]

The table would look like

1 | 2010-07-30 00:00:00 | 0.25 | 0.25 | [uuid] //still need to use 6.20  
2 | 2010-08-12 00:00:00 | 1.75 | 1.75 | [uuid] //still need to use 4.45 
3 | 2010-08-17 00:00:00 | 8.25 | 4.45 | [uuid] //we now have 3.80 remaining 
4 | 2010-09-15 00:00:00 | 0.05 | 0.00 | [uuid] //this row is untouched 

but I have a complete mind blank on how to do this efficiently or at all for that matter.

  • 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-24T07:56:08+00:00Added an answer on May 24, 2026 at 7:56 am

    Will it work for you? (Updated version)

    UPDATE table1 t3
    INNER JOIN
    (
    SELECT t1.id, IFNULL(SUM(t2.amntGained),0) as total // 0 for the smallest date
    FROM table1 t1
    LEFT JOIN table1 t2 ON (t2.uuid = t1.uuid AND t2.dateGained < t1.dateGained)
    // LEFT JOIN,not INNER because "<" is used for joining, 
    WHERE uuid = 1
    GROUP BY t1.id
    )X  ON (X.id=t3.id)
    SET t3.amntUsed = IF(X.total+t3.amntGained <=6.25, t3.amntGained, 
     IF(6.25-X.total>0, 6.25-X.total,0))
    WHERE t3.uuid=1
    

    For your data:

    id - total - amntGained - X.total+t3.amntGained - 6.25-X.total>0 - new.amntUsed
    1  - 0     - 0.25      - 0.25                   - true             0.25
    2  - 0.25  - 1.75      - 2                      - true             1.75
    3  - 2     - 8.25      - 10.25                  - true             6.25-2 = 4.25
    4  - 10.25 - 0.05      - 10.30                  - false            0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table in a MSSQL database that looks like this: Timestamp (datetime)
I have a table with some data that looks like: id | type |
I have a table in my SQL database that looks like: id type radius
I have a table that looks like that: The rows are sorted by CLNDR_DATE
I have a table that looks something like this: word big expensive smart fast
I have a table structure that looks like: <table> <tr id=row1> <td> <div>row 1
I have an HTML table that looks like this: ------------------------------------------------- |Column 1 |Column 2
I have a table that looks a bit like this actors(forename, surname, stage_name); I
I have a table named visiting that looks like this: id | visitor_id |
I have a database that contains a table that looks a bit like this:

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.