如何“按分钟排序(子查询)”?

发布于 2024-08-06 16:57:49 字数 609 浏览 5 评论 0原文

我正在尝试返回日期列表。每行都有多个日期连接为一个字符串。我想按每行中的最小日期对行进行排序。

这是我的查询:

  SELECT br.bm_tracking_number,
         (SELECT TOLIST(APPT.fact_date) 
            FROM bm_fact APPT 
           WHERE APPT.bm_review_sk = br.bm_review_sk
             AND APPT.fact_type_code=183050) "Appointments"
    FROM BM_REVIEW br
   WHERE row_delete_date_time IS NULL
ORDER BY MIN(SELECT APPT.fact_date 
               FROM bm_fact APPT
              WHERE APPT.bm_review_sk = br.bm_review_sk
               AND APPT.fact_type_code = 183050);

我在按行排序时收到 Oracle 错误(00936 缺少表达式)。还有另一种方法可以完成我想做的事情吗?

I am trying to return a list of dates. Each row has multiple dates concatenated as a single string. I want to order the rows by the minimum date in each row.

Here is my query:

  SELECT br.bm_tracking_number,
         (SELECT TOLIST(APPT.fact_date) 
            FROM bm_fact APPT 
           WHERE APPT.bm_review_sk = br.bm_review_sk
             AND APPT.fact_type_code=183050) "Appointments"
    FROM BM_REVIEW br
   WHERE row_delete_date_time IS NULL
ORDER BY MIN(SELECT APPT.fact_date 
               FROM bm_fact APPT
              WHERE APPT.bm_review_sk = br.bm_review_sk
               AND APPT.fact_type_code = 183050);

I am getting an Oracle error (00936 missing expression) on the order by line. Is there another way to accomplish what I am trying to do?

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

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

发布评论

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

评论(2

月野兔 2024-08-13 16:57:49

这:

  SELECT br.bm_tracking_number,
         TOLIST(bf.fact_date)
    FROM BM_REVIEW br
    JOIN BM_FACT bf ON bf.bm_review_sk = br.bm_review_sk
                   AND bf.fact_type_code = 183050
   WHERE br.row_delete_date_time IS NULL
GROUP BY br.bm_tracking_number
ORDER BY MIN(bf.fact_date)

...将为您提供一个列表,按 fact_date 升序排列。

This:

  SELECT br.bm_tracking_number,
         TOLIST(bf.fact_date)
    FROM BM_REVIEW br
    JOIN BM_FACT bf ON bf.bm_review_sk = br.bm_review_sk
                   AND bf.fact_type_code = 183050
   WHERE br.row_delete_date_time IS NULL
GROUP BY br.bm_tracking_number
ORDER BY MIN(bf.fact_date)

...will give you a list, ordered by the fact_date in ascending order.

原谅过去的我 2024-08-13 16:57:49

只看了一眼,但有一件事是您没有在子查询中将 bm_fact 别名为 APPT。

编辑:

好的,你解决了这个问题。

将 MIN() 放在子查询中怎么样?

ORDER BY (SELECT MIN(APPT.fact_date) ...)

Only glancing at it, but one thing is that you didn't alias bm_fact to APPT in the subquery.

EDIT:

Okay, you fixed that.

How about putting the MIN() inside the sub query?

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