Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Group by a generated column

Tags:

sql

hadoop

hive

I'm trying to group data by minutes, so I tried this query:

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;

Then hive tells me no such column,

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

So is it not supported by hive?

like image 450
daisy Avatar asked Feb 16 '23 06:02

daisy


1 Answers

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;

or and better

 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;
like image 195
Andrey Khmelev Avatar answered Feb 22 '23 20:02

Andrey Khmelev