共用方式為


window_time函式

適用於:核取記號為「是」 Databricks SQL 核取記號為「是」 Databricks Runtime 12.2 LTS 和更新版本

傳回由 windowsession_window 函式所產生之時間window 的內含結束時間。

語法

window_time(window)

引數

  • window:由 window 函式產生的 windowcolumn。

傳回

具有 window內含端點的 TIMESTAMP 值。 此值等同於 window.end - INTERVAL '0.000001' SECOND

範例

> SELECT a, window.start as start, window.end as end, window_time(window), cnt
    FROM (SELECT a, window, count(*) as cnt
           FROM VALUES ('A1', '2021-01-01 00:00:00'),
                       ('A1', '2021-01-01 00:04:30'),
                       ('A1', '2021-01-01 00:06:00'),
                       ('A2', '2021-01-01 00:01:00') AS tab(a, b)
           GROUP by a, window(b, '5 MINUTES'))
    ORDER BY a, window.start;
  A1  2021-01-01 00:00:00  2021-01-01 00:05:00  2021-01-01 00:04:59.999999 2
  A1  2021-01-01 00:05:00  2021-01-01 00:10:00  2021-01-01 00:09:59.999999 1
  A2  2021-01-01 00:00:00  2021-01-01 00:05:00  2021-01-01 00:04:59.999999 1