踏踏实实练SQLday1-2 lead/lag使用(股票波峰波谷)
2 lead/lag使用(股票波峰波谷)
波峰:当天的价格大于前一天和后一天
波谷:当天的价格小于前一天和后一天
select id,ds,price,case
when price>lag_price and price>lead_price then '波峰'
when price<lag_price and price<lead_price then '波谷' end as price_type
from(
select id,ds,price,lag(price,1)over(partition by.id order by ds) as lag_price,
lead(price,1)over(partition by.id order by ds) as lead_price
from test
)t
原文地址:https://blog.csdn.net/qq_45972323/article/details/144740844
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!