我需要有關如何比較同一列LogNum中的值以查找“不尋常”條目的幫助。例如,在我下面的LogTbl表中,我們可以看到,在ID號 4 上,LogNum條目與之前的條目模式相比大幅跳躍。
我如何比較這些LogNum條目并識別/輸出任何比前一個條目增加超過 5% 的條目,使用LogDate對條目進行老化?
| ID | 日志日期 | 對數 |
|---|---|---|
| 1 | 2006-05-26 00:00:00.000 | 112 |
| 2 | 2006-07-19 00:00:00.000 | 145 |
| 3 | 2006-09-08 00:00:00.000 | 162 |
| 4 | 2006-11-01 00:00:00.000 | 1787 |
謝謝。
uj5u.com熱心網友回復:
對于您的“大量”和“不尋常”這兩個詞沒有正式的標準。但是我想您可以嘗試選擇 LogNum 將在邊界內的記錄(LogNum >= MEAN(LogNum) - 2 * STDDEV(LogNum)) AND - LogNum <= MEAN(LogNum) 2 * STDDEV(LogNum))
uj5u.com熱心網友回復:
您的要求有很多解釋,一種可能的想法是使用平均值或標準偏差來確定閾值并過濾超過閾值的行。
with a as (
select *, avg(lognum) over() threshold
from t
)
select *
from a
where lognum > threshold
如果您只對相鄰行之間的差異感興趣,您可以使用lead,即找到值增加大于前一個值的 25% 的行
select Id, LogDate, Lognum
from (
select *, Lead(lognum) over(order by logdate) nxt
from t
)t
where nxt > lognum * 1.25
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/380037.html
