oracle中的子选择
我正在与 oracle 中的子选择作斗争。我想包括另一个表中的最新价格。
这是我当前的尝试:
SELECT tab1.*
(select price from
old_prices
where part_no=tab1.article_no
order by valid_from desc) as old_price,
FROM articles tab1
order by article_no
子选择返回几行,我认为这是问题所在。但我不知道如何限制Oracle中的行数。
I'm struggling with a subselect in oracle. I want to include the latest price from another table.
Here is my current attempt:
SELECT tab1.*
(select price from
old_prices
where part_no=tab1.article_no
order by valid_from desc) as old_price,
FROM articles tab1
order by article_no
The sub select returns several rows which I think is the problem. But I do not know how to limit the number of rows in Oracle.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
问候,
抢。
Regards,
Rob.
如果您要的是最新价格:
If it's the latest price you're after:
我想你指的是最新价格。
好吧,一开始这有点问题,有几种方法可以做到这一点:
似乎是最明显的选择,但效率相当低。
你可以尝试......
或者......
I presume you mean latest.
OK, well that's a bit of a problem to start with, there are several ways of doing this:
Seems the most obvious choice but its rather innefficient.
You could try....
Or....
要限制行数,请使用
ROWNUM < 10
。这是一个伪列,返回结果集每行的行号。编辑:
您需要添加另一个子选择查询(希望这是满足您需要的正确位置)
To limit rows use
ROWNUM < 10
. This is a pseudocolumn returning the row number of each line of your resultset.EDIT:
You need to add another subselect query (hope this is the right place for your need)
更有效的是
more efficient would be
这是另一种方法!
Here's another way!