apache-spark - Aliasing different WINDOW clauses in Spark SQL
问题描述
Is it possible to have aliases for multiple Windows
in the same query ?
For e.g. -
select
cust_id,
eff_dt,
row_number() over w AS rec1
from cust
WINDOW w AS (PARTITION BY cust_id ORDER BY eff_dt desc);
The above runs fine. But it fails when I try to add another Window
alias:
select
cust_id,
eff_dt,
row_number() over w AS rec1,
rank() over w2 AS rec2
from cust
WINDOW w AS (PARTITION BY cust_id ORDER BY eff_dt desc),
WINDOW w2 AS (PARTITION BY cust_id ORDER BY version asc);
Can anyone please help on how to use both the Window
aliases above ?
Thanks
解决方案
您可以使用嵌套查询来做到这一点,
select
cust_id,
eff_dt,
rec1,
rank() over w2 AS rec2
from (
select
cust_id,
eff_dt,
version,
row_number() over w AS rec1
from cust
WINDOW w AS (PARTITION BY cust_id ORDER BY eff_dt desc))
WINDOW w2 AS (PARTITION BY cust_id ORDER BY version asc);
推荐阅读
- java - java.security.SignatureException:对象未初始化以进行签名
- python - 如何对数据框列中的多个值求和,如果它们对应于另一列中的 1 个值
- google-sheets - 如何使用 arrayformula 引用以前的匹配记录?
- angular - textarea中JSON格式的格式字符串?
- msbuild - MSBuild 在错误的地方寻找 Microsoft.VisualBasic.Core.targets
- mysql - 未正确编码的 unicode 值
- javascript - DataTables - 请求的未知参数
- reactjs - How do I combine existing InputProps with additional InputProps in child component
- django - Add sitemap on external server to Django Sitemap
- javascript - Disable button if checkboxes are unchecked - across groups - in an ajax response