发现产品价格异常



有人给了我一个SQL问题,让我难住了,我想知道是否有人能告诉我最好的方法。

问题:给定表"product_price"表示产品在一段时间内的平均价格。范围内的所有天数都出现在"day"中。

价格($)

看起来下面应该会给你想要的结果:

with s as (
select *, 
Lag(Price, 1, Price) over(order by day) p,
Lead(Price, 1, Price) over(order by day) n
from prices
)
select day
from s
where p < Price and n < Price;

最新更新