title: How can I perform linear interpolation using oracle SQL?
body: <p>I am trying to use Oracle 11g (11.1 in dev, 11.2 in production) for numeric analysis, specifically linear interpolation on a table which has three columns of interest: a timestamp, a deviceid, and value.</p>
  
  <p>The value columns holds data from the device (with id deviceid), taken at the time given in the timestamp.  For example, this is bogus data, but it gives the idea:</p>
  
  <pre><code>     time       |  deviceid  |  value   
  ----------------|------------|-----------
   01:00:00.000   |  001       | 1.000
   01:00:01.000   |  001       | 1.030
   01:00:02.000   |  001       | 1.063 
   01:00:00.050   |  002       | 553.10
   01:00:01.355   |  002       | 552.30
   01:00:02.155   |  002       | 552.43 
  </code></pre>
  
  <p>The timestamps from device 001 do not match the timestamps of device 002, but I need to have the values from both device 001 and 002 in one row, with one timestamp, matching the timestamp for device 001.  What I want to end up with is something like this:</p>
  
  <pre><code>     time       |  device 001  |  device 002   
  ----------------|--------------|------------
   01:00:00.000   |  1.000       |  null
   01:00:01.000   |  1.030       |  552.520
   01:00:02.000   |  1.063       |  552.405
  </code></pre>
  
  <p>Where the value for device 002 was linearly interpolated based on the values for device 002 gathered at the two closest timestamps on either side of each timestamp for device 001.
  The null occurs because I don't have two timestamps for device 002 on either side of 01:00:00.000, and I don't want to extrapolate the value.</p>
  
  <p>From what I understand I can use percentile_cont to do this, but I don't understand the examples I have seen online.  For example, where would the percentile used by percentile_cont come from?  </p>
  
  <p>Thanks in advance for your help!</p>