【发布时间】:2016-12-08 04:00:14
【问题描述】:
我的查询如下所示:
select hour, count(*)
from table
group by hour
我希望返回看起来像:
hour count
8 1
9 0
10 3
但它看起来像:
hour count
8 1
10 3
这是因为 table 中没有 9 的条目。我能想到的唯一解决方案是使用围绕查询的 insert into 语句。所以,类似:
insert into (
select hour, count(*)
from table
group by hour)
values (9, 0)
但是这在 Spark SQL 中是不正确的语法。
是否可以插入到作为查询结果生成的表中而不将该表保存到数据库中?有没有其他方法可以完成我想要完成的事情?
【问题讨论】:
-
联合怎么样。 select hour, count(*) from table group by hour union select 9 ,0
-
返回
org.apache.spark.sql.AnalysisException: missing EOF at 'select' near 'union'; line 28 pos 0 -
stackoverflow.com/a/1271845/5308100 看到这个答案。应该做我相信的伎俩。
标签: sql apache-spark-sql apache-zeppelin