You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by wrstrs <wr...@foxmail.com> on 2021/01/04 12:52:05 UTC
function that computes across rows
Hi All,
Does Calcite support a custom function that computes across rows, such as a day-by-day ratio function which going to implement : DBD
Input:
SELECT
DBD(a) AS a_dbd
FROM
table_xx
WHERE
d = '20210101'
ORDER BY a_dbd
Convert to:
SELECT
CASE
WHEN a2 IS NULL OR a2 = 0 THEN 0
ELSE (a1 - a2) / a2
END AS a_dbd
FROM
(SELECT
SUM(a) AS a1
FROM
table_xx
WHERE
d = '20210101') t1
LEFT JOIN
(SELECT
SUM(a) AS a2
FROM
table_xx
WHERE
d = '20201231') t2 ON 1 = 1
ORDER BY a_dbd
Or a better expression...
Thanks
wrstrs