- Subscribe to RSS Feed
- Mark Question as New
- Mark Question as Read
- Float this Question for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
Hive Query not working
- Labels:
-
Apache Hive
Created 09-02-2016 09:34 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
> Not sure can use select min(from_date) clause
create table employees2_final stored as ORC tblproperties (‘orc.compress’=‘SNAPPY’) AS SELECT e.emp_no, e.birth_date,e.first_name, e.last_name, e.gender, select min(s.from_date) from new2_salaries s GROUP BY s.emp_no WHERE s.emp_no = e.emp_no as hire_date_new from employees e.
Created 09-06-2016 03:17 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
... and to add to what Predrag stated based on the documentation, the same is true for all other databases, including Oracle, PostgreSQL, etc. The query needs to be rewritten to achieve the expected result, first find the min(s.from_date) per s.emp_no and at the second step join with e.emp_no to retrieve the needed other fields, as lookups.
Try this:
SELECT e.emp_no, e.birth_date,e.first_name, e.last_name, e.gender, s.min_from_date FROM employees e, (SELECT emp_no, min(from_date) as min_from_date FROM new2_salaries GROUP BY s.emp_no) s WHERE s.emp_no = e.emp_no;
If any of the responses to your question addressed the problem don't forget to vote and accept the answer. If you fix the issue on your own, don't forget to post the answer to your own question. A moderator will review it and accept it.
Created 09-02-2016 09:47 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@sanjeevan mahajan
Can you try this out:
create table employees2_final stored as ORC tblproperties (‘orc.compress’=‘SNAPPY’) AS SELECT e.emp_no, e.birth_date,e.first_name, e.last_name, e.gender, min(s.from_date) from new2_salaries s, employees e WHERE s.emp_no = e.emp_nosel GROUP BY s.emp_no
Created 09-02-2016 09:53 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Created 09-02-2016 09:58 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@sanjeevan mahajan
How about this:
create table employees2_final stored as ORC tblproperties (‘orc.compress’=‘SNAPPY’) AS SELECT e.emp_no, e.birth_date,e.first_name, e.last_name, e.gender, min(s.from_date) from new2_salaries s, employees e WHERE s.emp_no = e.emp_nosel GROUP BY s.emp_no, s.from_date
Created 09-02-2016 10:07 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Created 09-02-2016 11:10 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have made quite few attempts - the ones that actually should work. Similar to
SELECT j.* FROM new2_salaries j WHERE j.from_date = (SELECT MIN(j2.from_date) FROM new2_salaries j2 WHERE j.empl_no = j2.empl_no);
Unfortunately, this is not working due to an existing bug: https://issues.apache.org/jira/browse/HIVE-8960
Created 09-02-2016 09:55 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@Daniel Kozlowski Please see attached screen grab screen-shot-2016-09-02-at-225412.png
Created 09-04-2016 04:50 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It doesn't work because, to quote the related wiki page: When using group by clause, the select statement can only include columns included in the group by clause, and aggregate functions on other columns. So, your query will work if you remove "group by" and "min".
Created 09-06-2016 03:17 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
... and to add to what Predrag stated based on the documentation, the same is true for all other databases, including Oracle, PostgreSQL, etc. The query needs to be rewritten to achieve the expected result, first find the min(s.from_date) per s.emp_no and at the second step join with e.emp_no to retrieve the needed other fields, as lookups.
Try this:
SELECT e.emp_no, e.birth_date,e.first_name, e.last_name, e.gender, s.min_from_date FROM employees e, (SELECT emp_no, min(from_date) as min_from_date FROM new2_salaries GROUP BY s.emp_no) s WHERE s.emp_no = e.emp_no;
If any of the responses to your question addressed the problem don't forget to vote and accept the answer. If you fix the issue on your own, don't forget to post the answer to your own question. A moderator will review it and accept it.
Created 09-06-2016 08:21 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@ Constantin Stanca : Thanks a lot for the help but Its is still giving semantic exception Invalid table alias or column reference 's': possible column names are emp_no, salary, from_date, to_date
