无法使Spark SQL datediff正常工作,也就是说,它可以运行,但不会显示结果。
我尝试了各种方法,最近一次是嵌套
select
guid,
first,
last,
datediff(last_string, first_string)
from (
select
guid,
first,
last,
cast(first as string) as first_string,
cast(last as string) as last_string
from (
select
guid,
min(entry_date) as first,
max(entry_date) as last
from my_table
group by guid
)
)
此查询有效(显示所有4个列),但添加datediff且仅显示3:guid,first,last
select
guid,
first,
last,
cast(first as string) as first_string,
cast(last as string) as last_string
from (
select
guid,
min(entry_date) as first,
max(entry_date) as last
from my_table
group by guid
)
编辑:我已验证datediff可以正常工作
select datediff('2012-12-31', '2011-12-31')
=> 366
答案 0 :(得分:-1)
尝试在括号中使用别名-最高的选择可能无法正确“看到”您期望的列。