Getting ParseException when running Hive query
up vote
0
down vote
favorite
I'm trying to find the number of employees who are paid less than average wage.
I'm pretty new to hive and struggling a bit, could someone explain whats wrong with my statement and help me out please?
My statement -
SELECT COUNT(*) FROM(SELECT wage, AVG(wage) AS avgWage FROM emp_wages) WHERE wage < avgWage;
The error -
ParseException line 1:82 cannot recognize input near 'where' 'wage' '<' in subquery source
Any help appreciated!
hadoop hive hql parseexception
add a comment |
up vote
0
down vote
favorite
I'm trying to find the number of employees who are paid less than average wage.
I'm pretty new to hive and struggling a bit, could someone explain whats wrong with my statement and help me out please?
My statement -
SELECT COUNT(*) FROM(SELECT wage, AVG(wage) AS avgWage FROM emp_wages) WHERE wage < avgWage;
The error -
ParseException line 1:82 cannot recognize input near 'where' 'wage' '<' in subquery source
Any help appreciated!
hadoop hive hql parseexception
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm trying to find the number of employees who are paid less than average wage.
I'm pretty new to hive and struggling a bit, could someone explain whats wrong with my statement and help me out please?
My statement -
SELECT COUNT(*) FROM(SELECT wage, AVG(wage) AS avgWage FROM emp_wages) WHERE wage < avgWage;
The error -
ParseException line 1:82 cannot recognize input near 'where' 'wage' '<' in subquery source
Any help appreciated!
hadoop hive hql parseexception
I'm trying to find the number of employees who are paid less than average wage.
I'm pretty new to hive and struggling a bit, could someone explain whats wrong with my statement and help me out please?
My statement -
SELECT COUNT(*) FROM(SELECT wage, AVG(wage) AS avgWage FROM emp_wages) WHERE wage < avgWage;
The error -
ParseException line 1:82 cannot recognize input near 'where' 'wage' '<' in subquery source
Any help appreciated!
hadoop hive hql parseexception
hadoop hive hql parseexception
asked Nov 9 at 19:52
Gus
766
766
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
up vote
1
down vote
accepted
A syntax error. Derived table should be aliased.
SELECT COUNT(*)
FROM (SELECT wage, AVG(wage) AS avgWage FROM emp_wages group by wage) t --alias needed here
WHERE wage < avgWage;
Query wise, it needs a change.
select count(*)
from (SELECT wage, AVG(wage) over() AS avgWage
FROM emp_wages
) t
where wage < avgWage
Your 2nd HQL is right. But isn't your 1st HQL need group by for aggregation
– saravanatn
Nov 10 at 1:40
1
You’re right..edited it to be syntactically correct.
– Vamsi Prabhala
Nov 10 at 4:34
add a comment |
up vote
0
down vote
SELECT COUNT(*)
FROM (SELECT wage, AVG(wage) AS avgWage FROM emp_wages group by wage)avg --group by needed
WHERE wage < avgWage;
add a comment |
up vote
0
down vote
The problem is AVG is an aggregation function. If you want to map one to many relations, you need to use a cross join function:
select
count(*), avg(v1.wage),
sum(case when v.wage < v2.avgwage then 1 else 0 end) below_average
from
emp_wages v cross join (select avg(wage) as avgwage from emp_wages) as v2
add a comment |
up vote
0
down vote
The correct query would be:
select count(*) where wage <(select avg(wage) from emp_wages);
You are getting a parsing error as wage and avgWage is in subquery.
add a comment |
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
A syntax error. Derived table should be aliased.
SELECT COUNT(*)
FROM (SELECT wage, AVG(wage) AS avgWage FROM emp_wages group by wage) t --alias needed here
WHERE wage < avgWage;
Query wise, it needs a change.
select count(*)
from (SELECT wage, AVG(wage) over() AS avgWage
FROM emp_wages
) t
where wage < avgWage
Your 2nd HQL is right. But isn't your 1st HQL need group by for aggregation
– saravanatn
Nov 10 at 1:40
1
You’re right..edited it to be syntactically correct.
– Vamsi Prabhala
Nov 10 at 4:34
add a comment |
up vote
1
down vote
accepted
A syntax error. Derived table should be aliased.
SELECT COUNT(*)
FROM (SELECT wage, AVG(wage) AS avgWage FROM emp_wages group by wage) t --alias needed here
WHERE wage < avgWage;
Query wise, it needs a change.
select count(*)
from (SELECT wage, AVG(wage) over() AS avgWage
FROM emp_wages
) t
where wage < avgWage
Your 2nd HQL is right. But isn't your 1st HQL need group by for aggregation
– saravanatn
Nov 10 at 1:40
1
You’re right..edited it to be syntactically correct.
– Vamsi Prabhala
Nov 10 at 4:34
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
A syntax error. Derived table should be aliased.
SELECT COUNT(*)
FROM (SELECT wage, AVG(wage) AS avgWage FROM emp_wages group by wage) t --alias needed here
WHERE wage < avgWage;
Query wise, it needs a change.
select count(*)
from (SELECT wage, AVG(wage) over() AS avgWage
FROM emp_wages
) t
where wage < avgWage
A syntax error. Derived table should be aliased.
SELECT COUNT(*)
FROM (SELECT wage, AVG(wage) AS avgWage FROM emp_wages group by wage) t --alias needed here
WHERE wage < avgWage;
Query wise, it needs a change.
select count(*)
from (SELECT wage, AVG(wage) over() AS avgWage
FROM emp_wages
) t
where wage < avgWage
edited Nov 10 at 4:33
answered Nov 9 at 20:16
Vamsi Prabhala
39.6k41939
39.6k41939
Your 2nd HQL is right. But isn't your 1st HQL need group by for aggregation
– saravanatn
Nov 10 at 1:40
1
You’re right..edited it to be syntactically correct.
– Vamsi Prabhala
Nov 10 at 4:34
add a comment |
Your 2nd HQL is right. But isn't your 1st HQL need group by for aggregation
– saravanatn
Nov 10 at 1:40
1
You’re right..edited it to be syntactically correct.
– Vamsi Prabhala
Nov 10 at 4:34
Your 2nd HQL is right. But isn't your 1st HQL need group by for aggregation
– saravanatn
Nov 10 at 1:40
Your 2nd HQL is right. But isn't your 1st HQL need group by for aggregation
– saravanatn
Nov 10 at 1:40
1
1
You’re right..edited it to be syntactically correct.
– Vamsi Prabhala
Nov 10 at 4:34
You’re right..edited it to be syntactically correct.
– Vamsi Prabhala
Nov 10 at 4:34
add a comment |
up vote
0
down vote
SELECT COUNT(*)
FROM (SELECT wage, AVG(wage) AS avgWage FROM emp_wages group by wage)avg --group by needed
WHERE wage < avgWage;
add a comment |
up vote
0
down vote
SELECT COUNT(*)
FROM (SELECT wage, AVG(wage) AS avgWage FROM emp_wages group by wage)avg --group by needed
WHERE wage < avgWage;
add a comment |
up vote
0
down vote
up vote
0
down vote
SELECT COUNT(*)
FROM (SELECT wage, AVG(wage) AS avgWage FROM emp_wages group by wage)avg --group by needed
WHERE wage < avgWage;
SELECT COUNT(*)
FROM (SELECT wage, AVG(wage) AS avgWage FROM emp_wages group by wage)avg --group by needed
WHERE wage < avgWage;
answered Nov 10 at 1:39
saravanatn
37617
37617
add a comment |
add a comment |
up vote
0
down vote
The problem is AVG is an aggregation function. If you want to map one to many relations, you need to use a cross join function:
select
count(*), avg(v1.wage),
sum(case when v.wage < v2.avgwage then 1 else 0 end) below_average
from
emp_wages v cross join (select avg(wage) as avgwage from emp_wages) as v2
add a comment |
up vote
0
down vote
The problem is AVG is an aggregation function. If you want to map one to many relations, you need to use a cross join function:
select
count(*), avg(v1.wage),
sum(case when v.wage < v2.avgwage then 1 else 0 end) below_average
from
emp_wages v cross join (select avg(wage) as avgwage from emp_wages) as v2
add a comment |
up vote
0
down vote
up vote
0
down vote
The problem is AVG is an aggregation function. If you want to map one to many relations, you need to use a cross join function:
select
count(*), avg(v1.wage),
sum(case when v.wage < v2.avgwage then 1 else 0 end) below_average
from
emp_wages v cross join (select avg(wage) as avgwage from emp_wages) as v2
The problem is AVG is an aggregation function. If you want to map one to many relations, you need to use a cross join function:
select
count(*), avg(v1.wage),
sum(case when v.wage < v2.avgwage then 1 else 0 end) below_average
from
emp_wages v cross join (select avg(wage) as avgwage from emp_wages) as v2
edited Nov 10 at 3:07
Pang
6,8011563101
6,8011563101
answered Nov 9 at 21:58
VIN
7411
7411
add a comment |
add a comment |
up vote
0
down vote
The correct query would be:
select count(*) where wage <(select avg(wage) from emp_wages);
You are getting a parsing error as wage and avgWage is in subquery.
add a comment |
up vote
0
down vote
The correct query would be:
select count(*) where wage <(select avg(wage) from emp_wages);
You are getting a parsing error as wage and avgWage is in subquery.
add a comment |
up vote
0
down vote
up vote
0
down vote
The correct query would be:
select count(*) where wage <(select avg(wage) from emp_wages);
You are getting a parsing error as wage and avgWage is in subquery.
The correct query would be:
select count(*) where wage <(select avg(wage) from emp_wages);
You are getting a parsing error as wage and avgWage is in subquery.
answered Nov 12 at 6:18
Ruben Bhattacharya
465
465
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53232448%2fgetting-parseexception-when-running-hive-query%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown