電錶讀數歸零復原SQL處理演算法

來源:互聯網
上載者:User

標籤:資料   sp   c   ef   r   演算法   bs   sql   as   

     在採集電錶資料的時候,可以發現有些電錶裝置讀數會發生復原。這時候,如果單純的累加計算用電量,就會出現負值。當然,這也許和電錶的品質有關係。

“RTQty”(當前讀到的讀數)、“LastQty”(上次讀數)、“PrecedingQty”(前次讀數)、”ErrorFlag”(錯誤標示)、”IncreaseQty”(增量讀數)、“IncreaseQtyOlder”(前次增量讀數)。

--判斷錯誤發生標示位

if @ErrorFlag=0

begin

  --錯誤標示位為0,那麼計算本次的增量值

  set @[email protected] RTQty [email protected] LastQty;

 

end

else

begin

 --錯誤標示位為1,

--計算當前值和上次值的增量@IncreaseQty,

--計算當前值和前次值的增量[email protected]

 

 set @IncreaseQty= RTQty - LastQty;

 set @IncreaseQtyOlder= RTQty [email protected];

  if  @IncreaseQtyOlder>=0

  begin

      set @[email protected]

  end

end

 

 

if @IncreaseQty>=0        ---如果增量不為負數

begin

    --更新指定裝置的資料點位,上次數值為當前值,更新前次數值為當前值,設定錯誤標示為0。

    update Meter set LastQty [email protected], PrecedingQty [email protected] RTQty,ErrorFlag=0  where  [email protected]

   --進行資料的其它計算

end

else

begin

    --更新指定裝置的資料點位,上次數值為當前值,設定錯誤標示為1。

    update Meter set LastQty [email protected],ErrorFlag=1  where  [email protected]

   

    --錯誤資訊插入到警報表

end

 

 

電錶讀數歸零復原SQL處理演算法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.