Peak and Valleys similar to argrelextrema in SQL

I am new to SQL. I want to find the peak and valleys in a timeseries data. I have a clickhouse DB and I can pull data into python where I can process this as mentioned in argrelextrema explained

However I am looking for a solution in SQL so I don’t have to transfer huge data between Clickhouse and python

I created a sample dataset in sqlfiddle

For reference,

Expected result
-- val is_pv
-- 1   1
-- 2   0
-- 3   0
-- 4   0
-- 5   0
-- 5   0
-- 5   0
-- 6   0
-- 7   1
-- 5   0
-- 3   0
-- 1   0
-- 1   1
-- 3   0
-- 5   0
-- 5   1
-- 3   1

Next Post

How To Treat Ulcers In The Mouth?

Thu Feb 3 , 2022
Do you feel irritation inside while talking or eating your food? Check out if you have developed a painful sore inside your mouth? These are called mouth ulcers. It is a very regular red lesion that injures the inner soft tissues in the mouth. However, mouth ulcers heal on their […]

You May Like