我有以下格式组按日期和获取特定领域的计数
'--------------------------------------
ID|col1 |date_ts
--------------------------------------
1 |type1 | 2011-10-01 23:59:59.163-08
2 |type1 | 2011-10-02 21:42:20.152-19
3 |type2 | 2011-10-03 23:21:49.175-21
4 |type3 | 2011-10-03 23:19:39.169-12
5 |type2 | 2011-10-05 23:34:30.129-01'
我想按日期,并得到每种类型的计数COL1
下表是输出I我试图实现
' date | type1 | type2 |type3 |
------------------------------------------
2011-10-01 | 1 | 0 | 0 |
2011-10-02 | 1 | 0 | 0 |
2011-10-03 | 0 | 1 | 1 |
2011-10-05 | 0 | 1 | 0 |'
我现在有下面的查询。但获取运行时错误。
'set hive.cli.print.header=true;
select
sum(if(col1 = 'type1', 1, 0)) as type_1,
sum(if(col1 = 'type2', 1, 0)) as type_2,
sum(if(col1 = 'type3', 1, 0)) as type_3
from table1 WHERE unix_timestamp(date_ts) >= unix_timestamp('2011-10-01 00:00:00.178-01') AND unix_timestamp (date_ts) <= unix_timestamp('2011-10-05 23:59:59.168-08')
GROUP BY col1, TO_DATE(date_ts)
ORDER BY date_ts;'
如何做到这一点的任何想法?谢谢
什么语言,你会被将其应用到? –
我正在尝试在蜂巢中执行 – dheee
您遇到的错误是什么? –