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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:27:05+00:00 2026-06-01T13:27:05+00:00

I am looking to update rows where the date column is NULL by averaging

  • 0

I am looking to update rows where the date column is NULL by averaging the dates of the nearest id before and nearest id after that row.

In the data below, it would update the row with ID 26 to be 2011-10-19

What MySQL statement would accomplish this?


Additional Notes:

The data looks something like this:

id     date           title
--------------------------------------------
12     2011-09-01     Example One
23     2011-10-02     Example Two
26     NULL           Example Three
27     2011-11-05     Example Four
29     2012-01-05     Example Five
37     NULL           Example Six
38     2012-02-03     Example Seven
--------------------------------------------

I would prefer not to use a procedure.

So far I’ve got…

UPDATE `table`
    SET `date`=
         (AVG(
              (SELECT `date` FROM `table` WHERE `id`< ID_OF_PARENT_QUERY AND `date` IS NOT NULL LIMIT 1),
              (SELECT `date` FROM `table` WHERE `id`> ID_OF_PARENT_QUERY AND `date` IS NOT NULL LIMIT 1)
         ))

    WHERE `date` IS NULL
  • 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-01T13:27:06+00:00Added an answer on June 1, 2026 at 1:27 pm
    UPDATE tableX AS t
      JOIN tableX AS next
        ON next.id =
           ( SELECT MIN(n.id)
             FROM tableX AS n
             WHERE n.id > t.id
               AND n.dateX IS NOT NULL
           )
      JOIN tableX AS prev 
        ON prev.id =
           ( SELECT MAX(p.id)
             FROM tableX AS p
             WHERE p.id < t.id
               AND p.dateX IS NOT NULL
           )
    SET t.dateX = prev.dateX + INTERVAL (DATEDIFF(next.dateX, prev.dateX) / 2) DAY
    WHERE t.dateX IS NULL
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking for the most efficient way to update a number of rows
I'm looking for the most Rails-y way to create a table that displays data
I'm looking to update certain rows based on specific criteria based on other rows.
I'm looking to create a view of a table which will highlight data that
Date column is created using colmodel below. This column shows values like 0101.0101.7070 for
I have an UPDATE sql command that modifies a Date/Time field in a particular
I need write an update statement that used multiple tables to determine which rows
I'm looking for the built-in MySQL information function that returns the number of rows
I'm looking to update a MySQL database with items from an RSS Feed. When
Looking at all the possibilites of creation / update columns in NHibernate I mostly

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.