sql - Extracting Unknown Dates -
i have 2 tables, employees , job_history. 2 tables have 3 columns identical: employee_id, job_id, , department_id.
i need display last_name , department_id employees table, date when each employee hits 20 year work anniversary.
the date when employees start work located in start_date job_history table. anniversary date needs displayed format: january twenty-third, nineteen eighty-two.
select e.last_name, e.department_id, count(*) "20 year anniversary" job_history l inner join employees e on e.department_id = l.department_id group e.department_id, e.last_name having count(*) = l.start_date + 20; now when run it, tells me isn't group function. how change proper syntax?
not sure why counting anything, never mind comparing count date. adding 20 date adds twenty days.
this might closer want:
select e.last_name, e.department_id, add_months(min(jh.start_date), 240) "20 year anniversary" employees e inner join job_history jh on jh.employee_id = e.employee_id group e.employee_id, e.last_name, e.department_id; the join between tables on emoloyee_id, because want earliest start date of job in department (presumably).
once have earliest date can add 20 years, 240 months.
you can read how format date string in documentation.
Comments
Post a Comment