如何 运行 hive 中的子查询

How to run a subquery in hive

我在 HIVE 中尝试 运行 这个查询:

select transaction_date, count(total_distinct) from (
SELECT transaction_date, concat(subid,'**', itemid) as total_distinct
FROM TBL_1
group by transaction_date, subid,itemid
) group by transaction_date

我想做的是获取 subid 和 itemid 的不同组合,但我需要每天的总计数。当我 运行 上面的查询时,我得到这个错误:

Error while compiling statement: FAILED: ParseException line 6:2 cannot recognize input near 'group' 'by' 'TRANSACTION_DATE' in subquery source

虽然我觉得查询是正确的。有人遇到过这个错误吗?

Hive 要求子查询使用别名,因此您需要为其指定一个名称:

select transaction_date, count(total_distinct) from (
SELECT transaction_date, concat(subid,'**', itemid) as total_distinct
FROM TBL_1
group by transaction_date, subid,itemid
) dummy  -- << note here
group by transaction_date

没错,错误消息一点帮助也没有。