Oracle 最小和最大列查询
好吧,需要一些帮助来创建 Oracle 10g DB 的查询。我有一个表如下所示:
----------------------------------------
| lowerBound | upperBound | locationId |
----------------------------------------
| 0 | 99 | 1 |
----------------------------------------
| 100 | 199 | 2 |
----------------------------------------
...
另一个表如下所示:
-----------------------------
| locationId | locationCode |
-----------------------------
| 1 | 12345 |
-----------------------------
| 2 | 23456 |
-----------------------------
| 3 | 34567 |
-----------------------------
...
我以一个数字开头,比如 113,但它是在 java 中计算出来的变量。我需要根据它落在 lowerBound 和 upperBound 列之间找出与该数字对应的 locationId,然后将其加入以找出第二个表中的 locationCode。我查过诸如 MIN/MAX 之类的东西,但是我没有找到我正在寻找的东西。我不是一个好的 DBA,因此感谢您的帮助。
Alright, need some help created a query for an Oracle 10g DB. I have a table to looks like this:
----------------------------------------
| lowerBound | upperBound | locationId |
----------------------------------------
| 0 | 99 | 1 |
----------------------------------------
| 100 | 199 | 2 |
----------------------------------------
...
Another table looks like this:
-----------------------------
| locationId | locationCode |
-----------------------------
| 1 | 12345 |
-----------------------------
| 2 | 23456 |
-----------------------------
| 3 | 34567 |
-----------------------------
...
I start with a number, say 113, but it is a variable figured out in java. I need to figure out the locationId that corresponds to that number, based on it falling between the lowerBound and upperBound columns, and then join that to figure out the locationCode in the 2nd table. I've looked up things like MIN/MAX and between, however I am not finding exactly what I am looking for. I am not a good DBA, so any help is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果 USING 部分让您感到困惑:
请注意,如果您的 lowerBound 和 upperBound 列是整数,则这将起作用。如果它们是 VARCHAR,那么您当然必须使用
TO_NUMBER
函数。If the USING part puzzles you:
Note that this will work if your lowerBound and upperBound columns are INTEGERS. If they are VARCHAR, you will have to use the
TO_NUMBER
function of course.