with coord(x,y) as( select21.34567 x , 122.23452 y unionall select21.12567 x , 121.23451 y unionall select21.2127 x , 122.27453 y unionall select21.1327 x , 122.24786 y unionall select122.2327 x , 22.34786 y unionall select122.2351 x , 21.13786 y unionall select121.1227 x , 21.12786 y ) select x , y --, case when x between 20 and 22 then y else x end lon , -- case when y between 121 and 123 then x else y end lat into temp coord from coord
--修正經緯度填寫錯誤的資料 update coord set x = casewhen x between20and22then y else x end , y = casewhen y between121and123then x else y end
--查看資料正確性 select * from coord
後來想到以前做連續性資料常常遇到信號 loss 造成精度或緯度為 -999 的狀況,可能也可以用類似的方法搭配視窗函數去偷捕資料(尚須修正)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
with coord(x,y) as( select21.337 x , 121.32451 y unionall select-999 x , 122.23452 y unionall select21.34567 x , -999 y unionall select21.12567 x , 121.23451 y unionall select21.2127 x , 122.27453 y ) select x , y , casewhen x = -999thenmin(x) over(rowsbetween1precedingand1preceding) else x end fix_x , casewhen y = -999thenmin(y) over(rowsbetween1precedingand1preceding) else y end fix_y from coord