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

  • Home
  • SEARCH
  • 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 80947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:22:57+00:00 2026-05-10T21:22:57+00:00

Here is a simple scenario with table characters: CharacterName GameTime Gold Live Foo 10

  • 0

Here is a simple scenario with table characters:

CharacterName GameTime Gold Live Foo 10 100 3  Foo 20 100 2  Foo 30 95 2 

How do I get this output for the query SELECT Gold, Live FROM characters WHERE name = 'Foo' ORDER BY GameTime:

Gold Live 100 3 0 -1 -5 0 

using MySQL stored procedure (or query) if it’s even possible? I thought of using 2 arrays like how one would normally do in a server-side language, but MySQL doesn’t have array types.

While I’m aware it’s probably easier to do in PHP (my server-side langauge), I want to know if it’s possible to do in MySQL, just as a learning material.

  • 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. 2026-05-10T21:22:57+00:00Added an answer on May 10, 2026 at 9:22 pm

    One possible solution using a temporary table:

    CREATE TABLE characters_by_gametime (   id INTEGER AUTO_INCREMENT PRIMARY KEY,   gold INTEGER,   live INTEGER);  INSERT INTO characters_by_gametime (gold, live) SELECT gold, live FROM characters ORDER BY game_time;  SELECT   c1.id,   c1.gold - IFNULL(c2.gold, 0) AS gold,   c1.live - IFNULL(c2.live, 0) AS live FROM   characters_by_gametime c1   LEFT JOIN characters_by_gametime c2     ON c1.id = c2.id + 1 ORDER BY   c1.id; 

    Of course Eoin’s solution is better if your id column follows the order you want in the output.

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

Sidebar

Ask A Question

Stats

  • Questions 117k
  • Answers 118k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer class Program { static void Main(string[] args) { Timer timer… May 11, 2026 at 10:50 pm
  • Editorial Team
    Editorial Team added an answer Use GROUP_CONCAT SELECT GROUP_CONCAT(bar) FROM TABLE GROUP BY foo; May 11, 2026 at 10:50 pm
  • Editorial Team
    Editorial Team added an answer Your code doesn't work because the function is not returning… May 11, 2026 at 10:50 pm

Related Questions

I hope this is a simple enough question for any SQL people out there...
I ran into a scenario where LINQ to SQL acts very strangely. I would
Does anyone have a process or approach to use for determining how to resove
I have a large system that I have coded and I wish to make

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.