这个 oracle 查询有什么问题?

发布于 2024-08-16 10:16:34 字数 535 浏览 10 评论 0原文

SELECT *
  FROM (SELECT ROWNUM rnum,
               query.*
         FROM  (WITH myQuery AS(
                     SELECT column_b
                       FROM table_a a
                     WHERE a.column_a = 1234)
         SELECT b.column_e AS some_column
           FROM table_b b,
                table_c c,
                table_a a
      LEFT JOIN table_d d ON c.column_c = d.column_d
           JOIN myQuery mq ON a.column_b = mq.column_b
          WHERE b.column_b = a.column_b) query)
 WHERE rnum > 0
SELECT *
  FROM (SELECT ROWNUM rnum,
               query.*
         FROM  (WITH myQuery AS(
                     SELECT column_b
                       FROM table_a a
                     WHERE a.column_a = 1234)
         SELECT b.column_e AS some_column
           FROM table_b b,
                table_c c,
                table_a a
      LEFT JOIN table_d d ON c.column_c = d.column_d
           JOIN myQuery mq ON a.column_b = mq.column_b
          WHERE b.column_b = a.column_b) query)
 WHERE rnum > 0

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鸠书 2024-08-23 10:16:34

不要混合 ANSI-88 和 ANSI-92 JOIN 语法,选择其中之一。这是使用 ANSI-92 语法的查询:

WITH myQuery AS (
  SELECT column_b
    FROM table_a a
   WHERE a.column_a = 1234)
SELECT x.*
  FROM (SELECT b.column_e AS some_column,
               ROWNUM 'rnum'
          FROM table_b b
          JOIN TABLE_A a ON a.column_b = b.column_b
          JOIN myQuery mq ON mq.column_b = a.column_b
          JOIN table_c c ON c.? = ?? --need join criteria here
     LEFT JOIN table_d d ON c.column_c = d.column_d) x
 WHERE x.rnum > 0

您的示例缺少 TABLE_C 连接的内容 - 因此 ???

我不知道 WITH 子句可以在子查询中定义 - 我确信我过去在 10g 中尝试它时遇到了错误。

Don't mix ANSI-88 and ANSI-92 JOIN syntax, pick one or the other. Here's your query using ANSI-92 syntax:

WITH myQuery AS (
  SELECT column_b
    FROM table_a a
   WHERE a.column_a = 1234)
SELECT x.*
  FROM (SELECT b.column_e AS some_column,
               ROWNUM 'rnum'
          FROM table_b b
          JOIN TABLE_A a ON a.column_b = b.column_b
          JOIN myQuery mq ON mq.column_b = a.column_b
          JOIN table_c c ON c.? = ?? --need join criteria here
     LEFT JOIN table_d d ON c.column_c = d.column_d) x
 WHERE x.rnum > 0

Your example lacks what TABLE_C joins on to - hence the ? and ??

I didn't know that WITH clauses can be defined in subqueries - I was sure I'd encountered an error in the past when attempting it in 10g.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文