sql - 按生成的列分组

标签 sql hadoop hive

我试图按分钟对数据进行分组,所以我尝试了这个查询:

SELECT FROM_UNIXTIME(
     unix_timestamp (time, 'yyyy-mm-dd hh:mm:ss'), 'yyyy-mm-dd hh:mm') as ts,
     count (*) as cnt 
     from toucher group by ts limit 10;

然后 hive 告诉我没有这样的列,

FAILED: SemanticException [Error 10004]: Line 1:134 Invalid table alias or column reference 'ts': (possible column names are: time, ip, username, code)

那么hive不支持吗?

最佳答案

SELECT FROM_UNIXTIME(unix_timestamp (time, 'yyyy-mm-dd hh:mm:ss'), 'yyyy-mm-dd hh:mm') as ts,
     count (*) as cnt 
from toucher 
group by FROM_UNIXTIME(unix_timestamp (time, 'yyyy-mm-dd hh:mm:ss'), 'yyyy-mm-dd hh:mm') limit 10;

或者更好

 select t.ts, count(*) from
(SELECT FROM_UNIXTIME(unix_timestamp (time, 'yyyy-mm-dd hh:mm:ss'), 'yyyy-mm-dd hh:mm') as ts             
    from toucher ) t
    group by t.ts limit 10;

关于sql - 按生成的列分组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18842259/

相关文章:

sql - 如何在分页前获取不同行的总数?

mysql - 在使用自动增量的 MySQL 中清理表

hadoop - Hadoop DataNode 错误 : host:port authority

hadoop - 如何增加 hive 中的 reducer ?

hadoop - 根据另一个表更新配置单元表中的列

sql - 使用 MAX() 时避免子选择

java - 将 org.jooq.TableField<Long> 转换为 org.jooq.TableField<BigDecimal>

csv - 使用 beeline 引用 csv 输出

hadoop - 配置单元:使用带分隔符的 collect_set

hadoop - 配置单元查询生成需要很长时间才能生成数据集