Reputation: 161
In SQL we have partion by and group by
select deptno, count(*) c from emp group by deptno;
DEPTNO C
------ -
10 3
20 5
30 6
select deptno, count(*) over (partition by deptno) c from emp;
DEPTNO C
------ -
10 3
10 3
10 3
20 5
20 5
20 5
20 5
20 5
30 6
30 6
30 6
30 6
30 6
30 6
If we need to practice the same thing in HIVE what will be the option . Do we have the same in Hive? Pls suggest
Thanks in Advance.
Upvotes: 1
Views: 431
Reputation: 702
same problem ..
I tried Windowing and Analytics Functions. .
FAILED: ParseException line 1:29 missing FROM at '(' near '(' in subquery source line 1:30 cannot recognize input near 'PARTITION' 'BY' 'salary' in subquery source
Upvotes: 0
Reputation: 294187
Hive supports windowing functions, see Windowing and Analytics Functions. So is really exactly as you posted:
select deptno, count(*) over (partition by deptno) c from emp;
The trick is that you need to be on a Hive that is recent enough to have the windowing functions. The linked page shows these were introduced in Hive 0.11.
As for the first query select deptno, count(*) c from emp group by deptno;
that is just an ordinary aggregate, I think was supported in v. -1 ...
Upvotes: 1