问题描述
在 MySQL 中,我可以有这样的查询:
In MySQL, I can have a query like this:
其中 GROUP BY
中的 timeHour
是选择表达式的结果.
where timeHour
in the GROUP BY
is the result of a select expression.
但是我刚刚尝试了一个类似于 Sqark SQL
中的查询,我得到了一个错误
But I just tried a query similar to that in Sqark SQL
, and I got an error of
我对 Spark SQL
的查询是这样的:
My query for Spark SQL
was this:
这个结构在 Spark SQL
中可行吗?
Is this construct possible in Spark SQL
?
推荐答案
这个结构在 Spark SQL 中可行吗?
Is this construct possible in Spark SQL?
是的,是.您可以通过两种方式使其在 Spark SQL 中工作,以在 GROUP BY
和 ORDER BY
子句中使用新列
Yes, It is. You can make it works in Spark SQL in 2 ways to use new column in GROUP BY
and ORDER BY
clauses
使用子查询的方法一:
方法 2 使用 WITH//优雅的方式:
在 Scala 中使用 Spark DataFrame(wo SQL) API 的替代方法:
这篇关于在“GROUP BY"中重用选择表达式的结果;条款?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!