gpt4 book ai didi

sql - oracle中给定数字之前最接近的数字

转载 作者:行者123 更新时间:2023-12-02 06:56:28 27 4
gpt4 key购买 nike

我在从给定数字中获取最近的数字时遇到问题(这个给定数字来自不同的表)

要求是:

Table A

Person Person_Entry_No

1 100

1 200

1 400
Table B

Person Person_Test

1 300

我需要输出为

一个人去参加测试时(person_test)的最近条目号(之前)

Person  Person_entry_no

1 200

我尝试使用 LIMIT 1 从表 1 中只获取一条记录......但它不起作用。

最佳答案

Oracle 企业数据库不支持

limit。相反,您可以使用 fetch first 子句:

SELECT a.*
FROM a
JOIN b ON a.person = b.person AND a.person_entry_no < b.person_test
ORDER BY a.person_entry_no DESC
FETCH FIRST 1 ROW ONLY

关于sql - oracle中给定数字之前最接近的数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30421934/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com