Web Analytics Made Easy -
StatCounter Searching and Calculating Minimum Years of experience - CodingForum

Announcement

Collapse
No announcement yet.

Searching and Calculating Minimum Years of experience

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Searching and Calculating Minimum Years of experience

    I was trying to calculate an employees total years of experience and i got the answer here Calculating date difference - CodingForum . Adding to that, i am trying to select all the employees who have minimum experience of 3 years.

    I tried something like this
    Code:
    SELECT e.fname, e.lname, e.pan_no FROM employees e INNER JOIN employee_deatils ed ON e.id=ed.eemp_id WHERE (SELECT ROUND(SUM(DATEDIFF( IF(ed.leaving_date is null or ed.leaving_date = '' or ed.leaving_date='0000-00-00', CURRENT_DATE(), ed.leaving_date), ed.joining_date ))/365,0)=3 group by ed.eemp_id)
    But it wont return any result (there is a record which has 3 yrs experience)
    if i do like this
    Code:
    SELECT e.fname, e.lname, ROUND(SUM(DATEDIFF( IF(ed.leaving_date is null or ed.leaving_date = '' or ed.leaving_date='0000-00-00', CURRENT_DATE(), ed.leaving_date), ed.joining_date ))/365,0) AS Diff from employees e INNER JOIN employee_deatils ed ON e.id=ed.eemp_id group by ed.eemp_id
    it returns 2 record with 0 and 3 years.
    Can somebody suggest where exactly i need to compare the data.
    Last edited by Mythri; Mar 3, 2022, 07:17 PM.

  • #2
    Please can some admin move this question under PHP , by mistake i have posted under MySQL

    Comment


    • #3
      No, I’ve deliberately moved it here, because this looks like MySQL to me, not like PHP. Besides, there is a redirection link to this thread from the PHP forum, so people will still see it there (for one week).
      Stop solving problems you don’t yet have!

      Comment


      • #4
        hey,
        if possible, can someone solve this too, I am new to MySQL and had a similar doubt?

        Comment

        Working...
        X