mysql - Sorting data from tables according to time with a level of accuracy in datetime -


I have two tables which are datetime and dual

which looks like this:

  mysql> Choose * from one; | Mysql & gt; Choose from two * + --------------------- + ---------- + | + --------------------- + ---------- + | Date | Price | | | Date | Price | + --------------------- + ---------- + | + --------------------- + ---------- + | 2002-03-18 10:30:02 | -181.241 | | | 2002-03-18 10:30:00-188.192. | 2002-03-18 10:30:06 | -180.673 | | | 2002-03-18 10:30:04 | -187.619 | | 2002-03-18 10:30:10 | -180.055 | | | 2002-03-18 10:30:08 | -187.032 | | 2002-03-18 10:30:14 | -179.459 | | | 2002-03-18 10:30:12 | -186.418 | | 2002-03-18 10:30:18 | -178.801 | | | 2002-03-18 10:30:16 | -185.807 |   

I am trying to do a query on values ​​from each tables with a normal date column (using the request as a reference). However, in some cases there is no symmetrical date in the measurement. The above example is an example of a period (this is the worst case), here the value of the table two corresponds to the values ​​in the table after two times.

To sort the values ​​of the two tables according to the time, I want to allow "sorting accuracy", which is the maximum time difference between the measure of an "event". This accuracy is 2 seconds in this case.

How I did not want to see: If the time difference between a data and two dataets is less than -2 seconds; Join Price from two in one:

  mysql> Choose * from one; + --------------------- + ---------- + ----------- + | Date | ValueONE | ValueTWO | + --------------------- + ---------- + ---------- + | 2002-03-18 10:30:02 | -181.241 | -188.192 | 2002-03-18 10:30:06 | -180.673 | -187.619 | | 2002-03-18 10:30:10 | -180.055 | -187.032 | | 2002-03-18 10:30:14 | -179.459 | -186.418 | | 2002-03-18 10:30:18 | -178.801 | -185.807 |   

If the difference is greater than + 2 seconds, discard the measurement. This is what I have tried, yet the following questions are based on the question given below.

  Choose one option, one. Price, two data, two Attribute one to two from ONE.date = TWO.date + INTERVAL 1 second or a date = TWO.date   

Is the possibility of being included in the included Statement such as

  if SELECT TIMESTAMPDIFF (second, '2002-03-18 10:30:02', '2002-03-18 10:30:00') & lt; = 2, then join    

You can use Batven:

  SELECT ONE.date, one.value value_ONE, two           Div> 

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -