查询不工作。也许“分组依据”有问题。怎么了?
Posted
技术标签:
【中文标题】查询不工作。也许“分组依据”有问题。怎么了?【英文标题】:The query is not working. Perhaps there is a problem with 'group by'. What's wrong? 【发布时间】:2019-07-17 09:31:44 【问题描述】:查询不工作。怎么了?
Hive 查询:
create Table copy_table
as select * from old_table as old
where column_A = 'ABC'
and column_B is null
and column_C = 'VAL'
group by column_D
order by column_E desc
错误信息:
Error while compiling statement: FAILED: SemanticException [Error 10025]: Expression not in GROUP BY key p_dt
【问题讨论】:
请看***.com/questions/5746687/… 在查询时创建表?这很令人困惑。你有语法错误。 由于您不小心标记了 mysql,因此可以找到有关您为什么不能这样做的解释(不限于 MySQL),例如here(MySQL 允许这样做很长一段时间,然后在 MySQL 5.7 中停止允许,所以出现了很多关于这个特定问题的问题) 【参考方案1】:如果未聚合,所有列都应聚合或包含在group by
中。并且您选择了所有列 *
并且只有一个列包含在 group by
中。
包含 group by 中的所有列或使用 min()、max() 等聚合所有其他列。当您进行 group by 时,选择中的所有列都应包含在聚合或 group by 中。
【讨论】:
以上是关于查询不工作。也许“分组依据”有问题。怎么了?的主要内容,如果未能解决你的问题,请参考以下文章