如何使用 Firebird DB 查找数字是否可以包含在 Delphi 的特定范围内?
How to find if a number can be contained in a specific range in Delphi using Firebird DB?
我有一个 table,其中包含不同尺寸的特定金属零件的价格。
为了找到合适的价格,我需要找到直径在尺寸范围内的字段。
可能因为第一次订购特殊尺寸或未生产零件,如非常小的零件 -> 1-9,所以该范围不存在。
例如:
直径D为37的零件应该找到用X指定的价格P(因为37在35-49的范围内)。
D(mm) : 10 | 20 | 30 | 35 | 50 | 60 |
P($) : 45 | 46 | 70 | X | 89 | 100 |
如何使用 SQL 请求 Firebird 数据库在我的 Delphi 代码中实现这一点?
您可以select使用过滤和限制为一行的一行:
select first 1 t.*
from t
where t.d <= 37
order by t.d desc;
到select第一个直径小于或等于想要的直径
select price
from component_price
where diameter <= 37
order by diameter desc
fetch first row only
请注意,fetch first row only
was introduced in Firebird 3. If you're using an earlier version, you will need to use FIRST
or ROWS
。
我有一个 table,其中包含不同尺寸的特定金属零件的价格。 为了找到合适的价格,我需要找到直径在尺寸范围内的字段。
可能因为第一次订购特殊尺寸或未生产零件,如非常小的零件 -> 1-9,所以该范围不存在。
例如:
直径D为37的零件应该找到用X指定的价格P(因为37在35-49的范围内)。
D(mm) : 10 | 20 | 30 | 35 | 50 | 60 |
P($) : 45 | 46 | 70 | X | 89 | 100 |
如何使用 SQL 请求 Firebird 数据库在我的 Delphi 代码中实现这一点?
您可以select使用过滤和限制为一行的一行:
select first 1 t.*
from t
where t.d <= 37
order by t.d desc;
到select第一个直径小于或等于想要的直径
select price
from component_price
where diameter <= 37
order by diameter desc
fetch first row only
请注意,fetch first row only
was introduced in Firebird 3. If you're using an earlier version, you will need to use FIRST
or ROWS
。