我试图通过加入另一个表来获取与min(date)相关联的行中的某些列。
我在Hive中使用它。
我的查询是:
With temp1 as
(Select employee_id as emp_id, min(date) as min_date from employee where employee_id in (select employee_id from employee_sal) group by employee_id)
Select
employee_sal.dept_code,
Temp1.emp_id,
employee_sal.dept_name,
employee_sal.paid_loc,
employee_sal.country_paid,
min_date
from employee_sal inner join temp1 on employee_sal.employee_id = emp1.employee_id
但我需要dept_name,paid_loc,country_paid基于min(date)基于employee表,如下所示:
employee_sal.dept_code,Temp1.emp_id,temp1.dept_name,temp1.paid_loc,temp1.country_paid,min_date
这些应该是与员工的最小(日期)相关联的值。
答案 0 :(得分:0)
With temp1 as
(Select employee_id as emp_id, min(date) as min_date from employee where employee_id in (select employee_id from employee_sal) group by employee_id)
Select
employee_sal.dept_code,
Temp1.emp_id,
employee_sal.dept_name,
employee_sal.paid_loc,
employee_sal.country_paid,
min_date
from employee_sal inner join temp1 on employee_sal.employee_id = emp1.employee_id And employee_sal.min_date = emp1.min_date