繁体   English   中英

如何在 where 子句中使用多行?

[英]How can I use multiple rows in where clause?

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 中,您可以使用相关子查询来获取下一个值。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM