Results 1 to 7 of 7

Thread: period difference between 2 dates in emp table

  1. #1
    Junior Member
    Join Date
    Nov 2007
    Answers
    1

    period difference between 2 dates in emp table

    Please can anybody send me the query to find the period between 2 employees in emp table based on hiredate.


  2. #2
    Expert Member
    Join Date
    Apr 2007
    Answers
    500

    Re: period difference between 2 dates in emp table

    Select Hiredate,lead(hiredate,1) over (order by hiredate) next_hiredate,round(months_between(lead(hiredate,1) over (order by hiredate),hiredate),3) Months from emp


  3. #3
    Expert Member
    Join Date
    Apr 2007
    Answers
    500

    Re: period difference between 2 dates in emp table

    That depends on ur Interest and Concentration.


  4. #4
    Junior Member
    Join Date
    Dec 2007
    Answers
    1

    Re: period difference between 2 dates in emp table

    hey

    how can we get those details using just the SQL Qerying.


  5. #5
    Moderator
    Join Date
    Jun 2007
    Answers
    2,074

    Re: period difference between 2 dates in emp table

    Quote Originally Posted by rama_kota View Post
    hey

    how can we get those details using just the SQL Qerying.
    The previous solution provided by our expert is SQL only.


  6. #6
    Junior Member
    Join Date
    Dec 2007
    Answers
    4

    Re: period difference between 2 dates in emp table

    Hi,

    The answer provided with LEAD and OVER gives you the difference between only successive employees.

    If the question is to get difference between all employees, then its better to use a cross join and get difference between hire_dates:

    select hire_date,startdate,(hire_date-startdate) diff
    from employees e,
    (select employee_id,hire_date startdate from employees) d
    where e.employee_id<>d.employee_id;


    Or, if its to get the difference between 2 specified dates:

    select hire_date,startdate,
    round(months_between(startdate,hire_date)) MonthsBetw
    from employees,(select hire_date startdate from employees
    where employee_id=&empid1)
    where employee_id=&empid2;

    Bye.


  7. #7
    Expert Member
    Join Date
    Apr 2007
    Answers
    500

    Re: period difference between 2 dates in emp table

    Quote Originally Posted by indira.s View Post
    Hi,

    The answer provided with LEAD and OVER gives you the difference between only successive employees.

    If the question is to get difference between all employees, then its better to use a cross join and get difference between hire_dates:

    select hire_date,startdate,(hire_date-startdate) diff
    from employees e,
    (select employee_id,hire_date startdate from employees) d
    where e.employee_id<>d.employee_id;


    Or, if its to get the difference between 2 specified dates:

    select hire_date,startdate,
    round(months_between(startdate,hire_date)) MonthsBetw
    from employees,(select hire_date startdate from employees
    where employee_id=&empid1)
    where employee_id=&empid2;

    Bye.
    startdate is not a field in emp .The question is period between 2 employees in emp table based on hiredate.

    Last edited by susarlasireesha; 12-14-2007 at 05:34 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact