SQL Server善用LOG10 和POWER 函數

來源:互聯網
上載者:User
MSDN聯機註解:LOG10 和POWER 函數是彼此反向關聯。例如,10^ LOG10(n) = n。只有一個值的轉換時沒問題,以下測測結果集。;WITH CAS(SELECT number FROM master..spt_values WHERE number BETWEEN 1 AND 10 AND type IN('P'))SELECT POWER(10,SUM(LOG10(number))) FROM C/*3628800*/--用一個變量驗證一下DECLARE @i INTSET @i=1;WITH CAS(SELECT number FROM master..spt_values WHERE number BETWEEN 1 AND 10 AND type IN('P'))SELECT @i=@i*number FROM CSELECT @i/*3628800*/--相同正確go--改變一下測試數據DECLARE @T TABLE(number int)INSERT @Tselect 1 UNION ALL SELECT 2 UNION ALLSELECT 4SELECT POWER(10,SUM(LOG10(number))) FROM @T/*7*/DECLARE @i INTSET @i=1SELECT @i=@i*number FROM @TSELECT @i/*8*/--結果不正確了反而用自然對數的基底時,更準確。SELECT EXP(SUM(LOG(number))) FROM @T  /*8*/結論:在結果集乘積時,別用Log10對數,還是自定議函數穩定。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.