2017-06-27 2 views
0

dataset変更されていないレコードのクリーンアップ方法

私は自分のデータセットをクリーンアップしたいと考えています。左側は生データがどのように見えるかです。それは時間に基づく温度の読みです。あなたが使用することができます

select zone, temperature, time 
from (select t.*, 
      lag(temperature) over (partition by zone order by time) as prev_temperature 
     from t 
    ) t 
where prev_temperature is null or prev_temperature <> temperature; 
+1

使用しているデータベースで質問にタグを付けます。また、あなたの出力のロジックを説明しようとします。 –

答えて

0

を持っている場合は、行を削除したいですよleadを使用して次の行の値を取得し、次の行の値が同じ場合に行を削除します。

with cte as (select t.* 
      ,lead(temperature) over(partition by zone order by time) as next_temp 
      from tbl t 
      ) 
delete from cte 
where next_temp is not null and next_temp=temperature 
0

:私は基本的にほとんどのデータベースでサポートされているANSI標準lag()機能を使用し、あなただけの変更をしたい場合は、それ以上の行が同じ温度

関連する問題