当我将案例表达式传递到last_value函数时会发生什么

发布于 2025-01-28 08:38:52 字数 287 浏览 4 评论 0 原文

我的last_value函数看起来像这样

  •   last_value(
             案件 
                 当语句_1然后0
                 当语句_2然后1
                 当语句_3然后0
                 否则
             端忽略nulls)(按第1列订购按列2)
     

有人可以解释如果有表达情况,应该返回的last_value是什么值。 我了解通过一列经过时会发生什么,但是这些表达式没有任何线索。

My LAST_VALUE function looks somethin like this

  •      LAST_VALUE(
             CASE 
                 WHEN statement_1 then 0
                 WHEN statement_2 then 1
                 WHEN statement_3 then 0
                 ELSE NULL
             END IGNORE NULLS)  OVER (PARTITION BY column1 ORDER BY column2)
    

Can someone explains what value is the LAST_VALUE supposed to return if there is expression.
I understand what happens when a column is passed, but incase of such expressions no clue whatsoever.

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

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

发布评论

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

评论(2

泪意 2025-02-04 08:38:52

You can find the description and examples at https://docs.oracle.com/cd/E11882_01/server.112/e41084/functions085.htm#SQLRF00655
Regards...
Btw. the CASE ... END structure is just as you are selecting values from the table field but with If condition. It doesn't affect the LAST_VALUE function.
It is something like this:
CASE WHEN ID = 1 THEN 10 WHEN ID = 2 THEN 20 ELSE 99 END
where ID = 1 is Statement1, ID = 2 is Statement2 ... and so on..

哑剧 2025-02-04 08:38:52

就像您的案例表达方式本身一样...

SELECT
  *,
  LAST_VALUE(new_column IGNORE NULLS)
    OVER (PARTITION BY column1
              ORDER BY column2
    )
FROM
(
   SELECT
     *,
     CASE 
         WHEN statement_1 then 0
         WHEN statement_2 then 1
         WHEN statement_3 then 0
         ELSE NULL
     END
       AS new_column
   FROM
     your_table
 )
   sub_query

The same as if your case expression were itself a column...

SELECT
  *,
  LAST_VALUE(new_column IGNORE NULLS)
    OVER (PARTITION BY column1
              ORDER BY column2
    )
FROM
(
   SELECT
     *,
     CASE 
         WHEN statement_1 then 0
         WHEN statement_2 then 1
         WHEN statement_3 then 0
         ELSE NULL
     END
       AS new_column
   FROM
     your_table
 )
   sub_query
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文