簡體   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