2014-09-01 3 views
0

임팔라 쿼리 결과를 주별로 그룹화하는 방법? 예상되는 결과는주 단위로 그룹화하는 방법 Cloudera impala

userguid     eventtime 
0 66AB1405446C74F2992016E5 2014-08-01T16:43:05Z 
1 66AB1405446C74F2992016E5 2014-08-02T20:12:12Z 
2 4097483F53AB3C170A490D44 2014-08-03T18:08:50Z 
3 4097483F53AB3C170A490D44 2014-08-04T18:10:08Z 
4 4097483F53AB3C170A490D44 2014-08-05T18:14:51Z 
5 4097483F53AB3C170A490D44 2014-08-06T18:15:29Z 
6 4097483F53AB3C170A490D44 2014-08-07T18:17:15Z 
7 4097483F53AB3C170A490D44 2014-08-08T18:18:09Z 
8 4097483F53AB3C170A490D44 2014-08-09T18:18:18Z 
9 4097483F53AB3C170A490D44 2014-08-10T18:23:30Z 

:

date     count of different userguid 
2014-08-01~2014-08-07 40 
2014-08-08~2014-08-15 20 
2014-08-16~2014-08-23 10 

감사합니다 같은 데이터 보인다.

답변

3

eventtime 경우는 timestamp 저장된다

그렇지
SELECT TRUNC(eventtime, "D"), COUNT(DISTINCT userguid) 
FROM your_table 
GROUP BY TRUNC(eventtime, "D") 
ORDER BY TRUNC(eventtime, "D"); 

eventtime 경우는 string 저장된다

SELECT TRUNC(CAST(eventtime AS TIMESTAMP), "D"), COUNT(DISTINCT userguid) 
FROM your_table 
GROUP BY TRUNC(CAST(eventtime AS TIMESTAMP), "D") 
ORDER BY TRUNC(CAST(eventtime AS TIMESTAMP), "D"); 

TRUNC 기능에 대한 자세한 내용은 Cloudera Impala documentation on Date and Time Functions 참조.

+0

당신은 답을 설명 할 수 있습니까? 다음주 일요일부터 토요일까지 그룹화하는 방법은 무엇입니까? – MANU

0

임팔라에서 TRUNC (타임 스탬프, "D")는 요일을 찾는 것을 의미합니다. 임팔라 날짜 및 시간 기능 here을 살펴볼 수 있습니다. 예를 들어

:

select trunc(cast('2016-11-10' as timestamp), "D") 
+---------------------------------------------+ 
| trunc(cast('2016-11-10' as timestamp), 'd') | 
+---------------------------------------------+ 
| 2016-11-07 00:00:00       | 
+---------------------------------------------+ 

+---------------------------------------------+ 
| trunc(cast('2016-11-09' as timestamp), 'd') | 
+---------------------------------------------+ 
| 2016-11-07 00:00:00       | 
+---------------------------------------------+ 

+---------------------------------------------+ 
| trunc(cast('2016-11-11' as timestamp), 'd') | 
+---------------------------------------------+ 
| 2016-11-07 00:00:00       | 
+---------------------------------------------+ 
관련 문제