我正在尝试选择表格中最早日期1年内的所有行。我正在使用以下代码:
select *
from baskets a
where activitydate < (select date_add((select min(activitydate) mindate_a from baskets), 365) date_b from baskets)
limit 10;
但是收到以下错误消息:
Error while compiling statement: FAILED: ParseException line 1:55 cannot recognize input near 'select' 'date_add' '(' in expression specification
Total execution time: 00:00:00.338
有什么建议吗?
编辑: 使用此代码:
select *
from baskets a
where activitydate < (select date_add(min(activitydate), 365) from baskets)
limit 10;
我收到了这个错误:
Error while compiling statement: FAILED: ParseException line 1:55 cannot recognize input near 'select' 'date_add' '(' in expression specification
答案 0 :(得分:0)
我很想使用窗口函数:
select b.*
from (select b.*, min(activity_date) as min_ad
from baskets b
) b
where activity_date < add_months(min_ad, 12);
如果您确实希望语法有效,请尝试减少select
s:
where activitydate < (select date_add(min(activitydate), 365) from baskets)
答案 1 :(得分:0)
使用JOIN
而不是在子查询中选择。我不认为Hive支持使用<
条件选择where子句。从Hive 0.13开始,只能使用IN
和EXISTS
。
:Language Manual SubQueries
SELECT a.*
FROM baskets a
JOIN (SELECT DATE_ADD(MIN(b.activitydate), 365) maxdate
FROM baskets) b
ON a.activitydate < b.maxdate
LIMIT 10;