首先按照股票的代码分类,以时间排序
create table t2 as
select
code,time,price,row_number() over(partition by code order by time) rn
from t1;
最后通过case when then else end 求出波峰和波谷
select a.code,a.time,a.price,
case when b.price is null then "未知"
when c.price is null then "未知"
when a.price>b.price and a.price>c.price then "波峰"
when a.price<b.price and a.price<c.price then "波谷"
else "中间" end as mark,a.rn
from t2 a
left join
t2 b on a.code=b.code and b.rn=a.rn-1
left join
t2 c on a.code=c.code and c.rn=a.rn+1
order by a.code,a.rn;