SQL Interpolation of time. Is this Possible?

I have a table Named FAC_TABLE

Time (DateTime)_ | _Value (Number)
2008-02-01 10:16:04, _ | ___10
2008-02-01 10:18:04, _ | ___13
2008-02-01 10:19:04, _ | ___11
2008-02-01 10:20:04, _ | ___12
2008-02-01 10:21:04, _ | ___10
2008-02-01 10:23:04, _ | ___11
2008-02-01 10:24:04, _ | ___16
2008-02-01 10:25:04, _ | ___15
2008-02-01 10:27:04, _ | ___15

We have values according to time, with a common time interval. My need is for interpolation and obtain values at determined time interval say by 5 min'.
Is it possible to create a SQL query to get values interpolated in a certain period of time?
example of output: -.

Time (DateTime)_ | _Value (Number)
2008-02-01 10:16:04, _ | ___10
2008-02-01 10:21:04, _ | ___10
2008-02-01 10:26:04, _ | ___15
Here there is no time February 1, 2008 10:26:04 ' in Raw data but Interpolation will get the data according to time.

I can do this programmatically by getting all the values in the DB, but more iteration is needed to get the DB and for treatment. So I'm looking for a SQL solution. Is this Possible?
I'm using Oracle 11 g.

Published by: mCm on February 20, 2012 22:32

Hello

Welcome to the forum!

Of course, you can do it in pure SQL. Here's one way:

WITH     actual_values     AS
(
     SELECT     time
     ,     LEAD (time)  OVER (ORDER BY time)     AS next_time
     ,     value
     ,     LEAD (value) OVER (ORDER BY time)     AS next_value
     FROM     fac_table
)
,     desired_times     AS
(
     SELECT     min_time + ( (LEVEL * 5)
                  / (24 * 60)
                  )          AS time
     FROM     (
               SELECT      MIN (time)     AS min_time
               ,     MAX (time)     AS max_time
               FROM     fac_table
          )
     CONNECT BY     LEVEL <= 5 * ( (max_time - min_time)
                         * (14 * 60)
                         )
)
SELECT     d.time
,     a.value + ( (a.next_value  - a.value)
            * ( (d.time      - a.time)
              / (a.next_time - d.time)
              )
            )     AS interpolated_value
FROM     actual_values     a
JOIN     desired_times     d  ON     d.time     >= a.time
                  AND     d.time     <  a.next_time
;

Sorry, I'm not a database now, so I can't test this.

The above query assumes that fac_table.time is unique, and that fac_table.value is not NULL.

Published by: Frank Kulash, February 20, 2012 07:57

Tags: Database

Similar Questions

Maybe you are looking for

  • Firefox still block Adobe Flashplayer?

    I uninstalled my Adobe Flashplayer last month after that Mozilla has blocked. Now has been released by Mozilla?Thank you.

  • How to import bookmarks from before browser?

    I have Firefix installation on 2 laptops. The first installation taken all my favorites from my old front Browser. The second installation was not picking up my favorites, how can I get my favorites in Firefox?

  • Apple Dock of lightning - line level output?

    I have a question that maybe with that you audiophiles out there can help.  Descriptions and comments from the dock connector 30 pins for the pre at first touch screen iPod claimed (correctly I think) that the mini stereo 3.5 mm output port of these

  • PageWide Pro 577 HP MFP: HP PageWide Pro 577 MFP Printing with random pimples on some pages

    I have two problems with my new MFP HP PageWide Pro 577 eventhough I later installed the drivers and firmware: I printed more than 1,000 'professional' and a few pages of quality 'Présentation' on this week less 2 NEW printer. I believe all > 100 pri

  • Loss of CD/DVD driver on the upgrade to Windows 10

    I have a gateway all-in-One ZX4270 model which I updated from Windows 8.1 to 10.  Everything is OK except that I apparently lost my CD/DVD drive in the process.  He is still physically there, and he turns a drive when it is inserted, but the computer