2017-07-10 10 views
0

この問題は私の頭の中では問題です。共通の日付スタンプを検索してTank1レベル差を返すレポートを下の表から作成できますか?タイムスタンプの日が変更され、タンク充填プロセスごとにデータベースに3〜5のエントリが存在するような問題が発生することがあります。値の差とタイムスタンプの差が理想的でないSQLテーブルとの差

レポートには、タンクが最後のt_stampと最後のT1_Lotでどれだけ満たされたかが示されます。ここで

は、データツリー

ここ
index T1_Lot  Tank1Level Tank1Temp t_stamp  quality_code 
30  70517 - 1 43781.1875 120   7/10/2017 6:43 192 
29  70517 - 1 242.6184692 119   7/10/2017 0:54 192 
26  70617 - 2 242.6184692 119   7/10/2017 0:51 192 
23  70617 - 2 44921.03516 134   7/8/2017 14:22 192 
22  70617 - 2 892.652771 107   7/8/2017 8:29 192 
21  62917 - 3 892.652771 107   7/8/2017 8:28 192 
20  62917 - 3 42352.94141 124   7/6/2017 13:15 192 
19  62917 - 3 5291.829102 121   7/6/2017 8:06 192 
18  62917 - 2 5273.518066 121   7/6/2017 8:05 192 
17  60817 - 2 444.0375366 97   7/6/2017 7:23 192 
16  60817 - 2 476.0814819 97   7/5/2017 18:09 192 
11  62817 - 3 45374.23047 113   6/30/2017 11:38 192 

はレポートがどのように見えるかです。

At 7/10/2017 6:43 T1_Lot = 70517 - 1, Tank1Level difference = 43,629., and took 5:52. 
At 7/8/2017 14:22 T1_Lot = 70517 - 1, Tank1Level difference = 44,028, and took 5:54. 
At 7/6/2017 13:15 T1_Lot = 62917 - 3, Tank1Level difference = 41877, and took 5:10. 

ここではその計算方法を示します。

Find the top time stamp with a value > 40,000 in Tank1Level, 
Then Find the Next > 40000 in Tank Level. 
Go one index up.. 
or it could be done with less than 8 hours accumulated 
as you can see from the second report line there is data that should be ignored. 
Report that last t_stamp of the series with the T1_Lot. 
Calculate the difference in Tank1Level and report 
Then Calculate the t_stamp difference in hh:mm and report. 

答えて

0

提供したデータに基づいて、自己結合が機能する場合があります。

from yourTable beforeFill join yourTable afterFill on beforeFill.t1_lot = afterFill.t1_lot 
    and beforeFill.index = afterFill.index - 1