sql - 计算Oracle中的极值数
问题描述
我在 Oracle 表中有 481 个整数。它们的值随机变化,它可以表示为一个函数,其中 x 从 1 变为 481,y 从 0 变为 15。如何计算这些数字的所有局部最大值和最小值点(极值)的数量?
解决方案
假设没有关系,您可以使用lead()
and lag()
:
select sum(case when y > prev_y and y > next_y then 1 else 0 end) as local_maxima,
sum(case when y < prev_y and y < next_y then 1 else 0 end) as local_minima
from (select t.*,
lag(y) over (order by x) as prev_y,
lead(y) over (order by x) as next_y
from t
) t
推荐阅读
- javascript - 为什么我没有从 React Native 中的 Object.entries 获得正确的结果?
- javascript - 我正在尝试使用 this.SetState() 更改组件的状态,但它不起作用
- python-3.x - 日期时间范围sqlalchemy列?
- firebase - 查询数据时出现Flutter平台错误
- javascript - 如何将离子阵列发送到 Firebase 数据库
- rust - Tokio core.run 无法编译。出现错误:特性 `futures::future::Future` 未针对 `impl futures::Future` 实现
- angular - Angular9 - 检查 Firebase 用户当前是否已登录
- android - MotionLayout 中的两个 Recycler 视图会产生问题
- python - 存储灰度视频的像素值,对它们进行平均,然后显示生成的视频
- azure-devops - Terraform 与私有 git repo / azure devops