在HiveQL中,如何为所有行和某些行选择结果并将它们显示在一个表中?
例如,我有一个“国家代码”列,我想要在一张表中提供所有“世界”以及一些国家的数据。
我尝试了一个案例,但我获得的最接近的是国家和世界其他地方:
select
case when lower(a.country) like 'cn' then 'China'
when lower(a.country) like 'us' then 'USA'
when lower(a.country) like 'uk' then 'UK'
when lower(a.country) like 'de' then 'Germany'
when lower(a.country) like 'jp' then 'Japan'
when lower(a.country) like 'br' then 'Brazil'
else "Rest"
end as Country,
c.D,
avg(case when a.time between 1 and 999999 then a.time else NULL end) as avg_time,
count(case when a.time between 1 and 999999 then a.time else NULL end) as time_count
from table1 a
join table2 c on a.vdate=c.cdate
and c.D like "2019_03"
group by c.D,
case when lower(a.country) like 'cn' then 'China'
when lower(a.country) like 'us' then 'USA'
when lower(a.country) like 'uk' then 'UK'
when lower(a.country) like 'de' then 'Germany'
when lower(a.country) like 'jp' then 'Japan'
when lower(a.country) like 'br' then 'Brazil'
else "Rest"
我还尝试将*
放在下面的country
列表中的另一个查询中,但这自然会出错:
select
c.D,
a.B,
avg(case when a.time between 1 and 999999 then a.time else NULL end) as
avg_time,
count(case when a.time between 1 and 999999 then a.time else NULL end) as time_count
from table1 a
join table2 c on a.vdate=c.date
where lower(a.country) in ("cn", "us", "uk", "de", "jp", "br")
and c.D like "2019_03"
group by c.D, a.B
如何在一个查询中查询所有世界和六个国家?