在执行涉及 FROM 子句中的子查询的 Hive 查询时出错

Getting an error while executing a Hive Query which involves a Subquery in the FROM Clause

我有一个 table 架构如下所示:

CREATE TABLE Table1 (`membertype` varchar(1));

INSERT INTO Table1 (`membertype`)
VALUES
    ('Y'),('H'),('U'),('W'),('W'),('W'),('H'),('H'),('U'),
    ('U'),('P'),('P'),(''),('P'),('P'),('P'),(''),('W'),
    ('Y'),('Y'),('Y'),('H'),('D'),('D'),('D'),('D'),('H'),
    ('W'),('W');

我想要实现的是获取列中每种类型的计数以及它们占列中类型总数的百分比。

我在 MYSQL 中测试了以下查询并得到了想要的结果:

select (case when m.membertype='Y' then 'Young Adult' 
    when m.membertype='H' then 'Head' 
    when m.membertype='W' then 'Spouse' 
    when m.membertype='P' then 'Aged Parent' 
    when m.membertype='U' then 'Unknown' 
    when m.membertype='D' then 'Deceased' else 'No Match' end) as type,
    count(*) as typecount,
    count(*)/t.total*100 as percentage from Table1 as m,
    (select count(*) as total from Table1) as t group by membertype;

type       typecount    percentage
No Match      2          6.8966
Deceased      4          13.7931
Head          5          17.2414
Aged Parent   5          17.2414
Unknown       3          10.3448
Spouse        6          20.6897
Young Adult   4          13.7931

**

Link

**

同一查询在 HIVE 中失败并出现以下错误:

select (case when h.member='Y' then 'Young Adult' 
when h.member='H' then 'Head' 
when h.member='W' then 'Spouse' 
when h.member='P' then 'Aged Parent' 
when h.member='U' then 'Unknown' 
when h.member='D' then 'Deceased' else 'No Match' end) as type,
count(*) as typecount,
count(*)/t.total*100 as percentage from hhinfo as h,
(select count(*) as total from hhinfo) as t group by member;


FAILED: SemanticException [Error 10025]: Line 1:277 Expression not in GROUP BY key 'total'

我在这里错过了什么?任何帮助将不胜感激。

尝试将 total 显式添加到 group by clause

...as t group by member, total