By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE Data (ID INT, Value INT)
INSERT Data
VALUES
(1, 26),
(2, 29),
(3, 32),
(4, 34),
(5, 36),
(6, 34),
(7, 33),
(8, 34),
(9, 36),
(10, 37)
SELECT ID, Value
FROM (
SELECT
*,
LAG(Value) OVER(ORDER BY Id) AS PreviousValue,
LEAD(Value) OVER(ORDER BY Id) AS FollowingValue
FROM Data
) A
WHERE (A.Value < PreviousValue OR PreviousValue IS NULL)
AND (A.Value < FollowingValue OR FollowingValue IS NULL)
SELECT ID, Value
FROM (
SELECT
*,
MIN(Value) OVER(ORDER BY Id ROWS BETWEEN 3 PRECEDING AND 3 FOLLOWING) AS LocalMinumum
FROM Data
) A
WHERE A.Value = LocalMinumum
ID | Value |
---|---|
1 | 26 |
7 | 33 |
ID | Value |
---|---|
1 | 26 |
7 | 33 |