c# - 如何在 where 子句中使用多行?
问题描述
TRAVEL | SIZE
0 | 0.41
2.5 | 0.45
5.0 | 0.50
7.5 | 0.54
10 | 0.58
我正在使用 Firebird 数据库。最终目标是根据给定的大小获得旅行。我面临的问题是给定的大小是连续的。
例如,给定大小为 0.47。然后,从插值公式得到旅行:(0.47-0.45)*(5.0-2.5)/(0.5-0.45)+2.5 = 3.5
实际上,在提取给定大小周围的 2 行之后,我尝试在 C# 中进行计算。但我被困在提取 2 行。
我该如何解决这个问题。
解决方案
lead()
为此,我建议:
select (case when 0.47 = size then travel
else travel + (next_travel - travel) * (0.47 - size) / (next_size - size)
end) as imputed_size
from (select t.*,
lead(size) over (order by size) as next_size,
lead(travel) over (order by size) as next_travel
from t
) t
where 0.47 >= size and
(0.47 < next_size or next_size is null);
在旧版本的 Firebird 中,您可以使用相关子查询来获取下一个值。
推荐阅读
- jenkins - Jenkins:解密 credentials.xml 中的所有密码(通过 Jenkins 执行控制台)
- node.js - 在 Ubuntu 18.04 上运行 Docker 在尝试 sudo docker-compose up 时出现错误 [/bin/sh 1] [:missing]
- amazon-web-services - 根据后缀(扩展名)创建 AWS S3 清单
- javascript - 悬停时预加载视频
- datetime - 如何修复 hive 中时间戳字段的导入?
- c# - 在 C# 中使用输入参数执行存储过程
- html - 两个不同 div 列中的行高度相等
- oracle - 如何在 Oracle 12c DB 中安排插入脚本
- r - 在两个不同大小的矩阵中查找匹配行的索引
- python - Python中Redis默认池中的连接数