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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:17:44+00:00 2026-05-25T10:17:44+00:00

I have some intraday stock data saved into a MySQL table which looks like

  • 0

I have some intraday stock data saved into a MySQL table which looks like this:

+----------+-------+
| tick     | quote |
+----------+-------+
| 08:00:10 |  5778 |
| 08:00:11 |  5776 |
| 08:00:12 |  5778 |
| 08:00:13 |  5778 |
| 08:00:14 |  NULL |
| 08:00:15 |  NULL |
| 08:00:16 |  5779 |
| 08:00:17 |  5778 |
| 08:00:18 |  5780 |
| 08:00:19 |  NULL |
| 08:00:20 |  5781 |
| 08:00:21 |  5779 |
| 08:00:22 |  5779 |
| 08:00:23 |  5779 |
| 08:00:24 |  5778 |
| 08:00:25 |  5779 |
| 08:00:26 |  5777 |
| 08:00:27 |  NULL |
| 08:00:28 |  NULL |
| 08:00:29 |  5776 |
+----------+-------+

As you can see, there are some points where no data is available (quote is NULL). What I would like to do is a simple step interpolation. This means each NULL value should be updated with the last value available. The only way I managed to do this is with cursors, which is pretty slow due to the large amount of data. I’m basically searching something like this:

UPDATE table AS t1
SET quote = (SELECT quote FROM table AS t2 
             WHERE t2.tick < t1.tick AND 
                   t2.quote IS NOT NULL 
             ORDER BY t2.tick DESC 
             LIMIT 1)
WHERE quote IS NULL

Of course this query will not work, but this is how it should look like.

I would appreciate any ideas on how this can be solved without cursors and temp tables.

  • 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-25T10:17:44+00:00Added an answer on May 25, 2026 at 10:17 am

    This should work:

    SET @prev = NULL;
    
    UPDATE   ticks
    SET      quote= @prev := coalesce(quote, @prev)
    ORDER BY tick;
    

    BTW the same trick works for reading:

    SELECT   t.tick, @prev := coalesce(t.quote, @prev)
    FROM     ticks t
    JOIN     (SELECT @prev:=NULL) as x -- initializes @prev
    ORDER BY tick
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some HTML like this (which I cannot change): <div> <p class=name> <span>Employee
I have some data- attributes that I put into a table row tag. When
I have some MySQL results like this: --------------------------- | name | something_random | ---------------------------
I have some perl code that looks something like this: my @array = map
I have some classes layed out like this class A { public virtual void
I have some code like this in a winforms app I was writing to
I have some javascript like this: <script> var num = 0; if(num==0){ function lol(){
i have some data saved in a xml file. Those will be displayed in
I have some submodules organized like this: |-- app | |-- models | |
I have some JSON that is sent to my webservice that looks something like

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.