无法让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 列(,但添加日期差异,它只显示 3:guid、第一个、最后一个
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
)
编辑:我已经验证了日期差异有效
select datediff('2012-12-31', '2011-12-31')
=> 366
尝试为括号提供别名 - 最高的选择可能无法正确"看到"您期望的列。