【发布时间】:2018-04-18 21:57:39
【问题描述】:
我正在尝试将 sql 语句从 ANSI 89 转换为 ANSI 92(意味着将“(+)”转换为“OUTHER JOIN”)
代码如下:
select a.*, p.price
from article a, prices p
where a.product_id = p.product_id(+)
and trunc(sysdate) + 1 between a.date_from and date_to
and trunc(sysdate) + 1 between p.date_from(+) and p.date_to(+);
我知道 (+) 指的是 LEFT 或 RIGHT JOIN,具体取决于放置它的位置,但我不知道如何转换最后一行 (
and trunc(sysdate) + 1 between p.date_from(+) and p.date_to(+)
)
到目前为止,我做了以下工作:
select a.*, p.price
from article a
left join prices p
on a.product_id = p.product_id
where trunc(sysdate) + 1 between a.date_from and date_to
但我不知道如何转换最后一个条件。
有人可以帮忙吗?
谢谢,
【问题讨论】:
-
如果您使用
left join,则不再需要(+)。关于不同的 ansi92 连接,here's an interesting older post 你可以阅读。此外,可以在left join的on中使用between标准(尽管很少这样做) -
and trunc(sysdate) + 1 between p.date_from and p.date_to;? -
@LukStorms:我的错误,我在尝试中忘记了“(+)”。无论如何,这篇文章很好,但已经知道 LEFT/RIGHT/INNER/FULL 连接之间的区别。我只想在 ANSI 92 中转换 p.date_from(+) 和 p.date_to(+) 之间的 and trunc(sysdate) + 1
-
@a_horse_with_no_name:它不工作。它限制了其余的条件并且不返回任何内容。
-
您需要将其放入
JOIN条件中,不是where条件中。
标签: sql oracle left-join ansi-sql