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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:36:25+00:00 2026-06-10T22:36:25+00:00

I have a table like this (simplified): +——+——–+ | tick | value | +——+——–+

  • 0

I have a table like this (simplified):

+------+--------+
| tick | value  |
+------+--------+
|    1 |     10 |
|    2 |     20 |
|    5 |     50 |
|    7 |     10 |
|   10 |     85 |
+------+--------+

I want to generate another table which includes all numbers from min(tick) to max(tick) as tick values:

+------+--------+
| tick | value  |
+------+--------+
|    1 |     10 |           * already exists
|    2 |     20 |           * already exists
|    3 |     30 | = 20 + 10
|    4 |     40 | = 30 + 10
|    5 |     50 | = 40 + 10 * already exists
|    6 |     30 | = 50 - 20
|    7 |     10 | = 30 - 10 * already exists
|    8 |     35 | = 10 + 25
|    9 |     60 | = 35 + 25
|   10 |     85 | = 60 + 25 * already exists
+------+--------+

To be clear,

  1. I have non-consecutive tick values and want to insert missing ticks.
  2. I want to do this to another table, so original table won’t be modified.
  3. values of missing ticks increases/decreases as equal steps from previous existing tick to next existing tick. As a psudo-formula:
    increment = (next_value - current_value) / (next_tick - current_tick)

How to manage this?

  • 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-10T22:36:27+00:00Added an answer on June 10, 2026 at 10:36 pm

    This stored procedure will do what you want, populating the table allticks

    CREATE PROCEDURE `tickster`()
    BEGIN
        DECLARE finished INT DEFAULT 0;
        DECLARE oldticks INT DEFAULT 0; -- initial ticks here
        DECLARE oldvalue INT DEFAULT 0; -- initial value here
        DECLARE newticks INT DEFAULT 0;
        DECLARE newvalue INT DEFAULT 0;
        DECLARE t INT DEFAULT 0;
        DECLARE v INT DEFAULT 0;
        DECLARE delta INT DEFAULT 0;
    
        DECLARE existing CURSOR FOR SELECT ticks,value FROM ticks ORDER BY ticks;
        DECLARE CONTINUE HANDLER FOR NOT FOUND SET finished=1;
    
        OPEN existing;
    
        nexttick: LOOP
            -- Get next value or break
            FETCH existing INTO newticks,newvalue;
            IF finished>0 THEN
                LEAVE nexttick;
            END IF;
    
            -- initialize a loop to cover the inexistant ticks
            SET t=oldticks+1;
            SET v=oldvalue;
            SET delta=(newvalue-oldvalue)/(newticks-oldticks);
    
            -- run the loop
            nextstep: LOOP
                IF t>=newticks THEN
                    LEAVE nextstep;
                END IF;
                -- calculate new interpolated value and write it to the table
                SET v=v+delta;
                INSERT INTO allticks SET ticks=t, value=v;
                SET t=t+1;
            END LOOP;
    
            -- write the existing value to the table
            INSERT INTO allticks SET ticks=newticks, value=newvalue;
    
            -- make new dataset the old dataset
            SET oldticks=newticks;
            SET oldvalue=newvalue;
    
        END LOOP;
    END
    

    Add the initial ticks and values where indicated, they are needed, if there is no row with ticks=1

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

Sidebar

Related Questions

We have a simplified table like this: TYPE; VALUE AA; 10 BB; 7 CC;
I have a table like this (simplified): ID | Name | Parent --------------------------------- 1
I have a table setup like this (simplified for example): user_id item_id click_dt Each
I have this existing schema where a schedule table looks like this (very simplified).
I have a table that looks something like this (simplified): *ScheduledReports* ReportID StartDate Frequency
Let's say I have a table like this (this is just a simplified example,
I have table (call it my_table ) that can be simplified like this: NAME,
I have a table, let's call it 'entries' that looks like this (simplified): id
I have a web-page that looks like this (simplified example) <table id=events_results_table> <thead> <tr>
We have a table like this (simplified version): Items: Itemid Itemname Itemfatherid itemA theitemA

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.