Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Employee Year Calculation

Employee Year Calculation

Scheduled Pinned Locked Moved Database
databasecomhelptutorialquestion
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jassim Rahma
    wrote on last edited by
    #1

    Hi, I have employees table with date_of_join field and I have employee_leaves table with the following fields: employee_id leave_from leave_to total_days the employee joined on 15 Feb 2011 I want to have a query showing the cound of leaves for every employee years based on his date_of_join for example, if the employee joined on 15 Feb 2011 then the result will be like this: Feb 2011 to feb 2012 ---- totals days: 21 Feb 2012 to feb 2013 ---- totals days: 26 Feb 2013 to feb 2014 ---- totals days: 8 where Feb to feb is the employee year so it's from 15 Feb to 14 Feb every year can anyone help please?

    Technology News @ www.JassimRahma.com

    L 1 Reply Last reply
    0
    • J Jassim Rahma

      Hi, I have employees table with date_of_join field and I have employee_leaves table with the following fields: employee_id leave_from leave_to total_days the employee joined on 15 Feb 2011 I want to have a query showing the cound of leaves for every employee years based on his date_of_join for example, if the employee joined on 15 Feb 2011 then the result will be like this: Feb 2011 to feb 2012 ---- totals days: 21 Feb 2012 to feb 2013 ---- totals days: 26 Feb 2013 to feb 2014 ---- totals days: 8 where Feb to feb is the employee year so it's from 15 Feb to 14 Feb every year can anyone help please?

      Technology News @ www.JassimRahma.com

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      What have you tried? :)

      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

      J 1 Reply Last reply
      0
      • L Lost User

        What have you tried? :)

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

        J Offline
        J Offline
        Jassim Rahma
        wrote on last edited by
        #3

        I am not able to get it... I tried:

        SELECT employee_leaves.leave_from, employee_leaves.leave_to FROM employee_leaves
        JOIN leave_category ON leave_category.leave_category_id = employee_leaves.leave_category
        GROUP BY YEAR(employee_leaves.leave_from);

        but this will just group by cal;ander year not employee year

        Technology News @ www.JassimRahma.com

        L 1 Reply Last reply
        0
        • J Jassim Rahma

          I am not able to get it... I tried:

          SELECT employee_leaves.leave_from, employee_leaves.leave_to FROM employee_leaves
          JOIN leave_category ON leave_category.leave_category_id = employee_leaves.leave_category
          GROUP BY YEAR(employee_leaves.leave_from);

          but this will just group by cal;ander year not employee year

          Technology News @ www.JassimRahma.com

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          You can only group on fields that are present within the query (or calculations based on one of those fields). You can get get the start of the contract by looking for a MIN-entry. Add 365 days to that fact, that's your range. That does not account for leap-years of course.

          Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

          Kornfeld Eliyahu PeterK 1 Reply Last reply
          0
          • L Lost User

            You can only group on fields that are present within the query (or calculations based on one of those fields). You can get get the start of the contract by looking for a MIN-entry. Add 365 days to that fact, that's your range. That does not account for leap-years of course.

            Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

            Kornfeld Eliyahu PeterK Offline
            Kornfeld Eliyahu PeterK Offline
            Kornfeld Eliyahu Peter
            wrote on last edited by
            #5

            Better add 1 year and not 365 day...

            I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)

            "It never ceases to amaze me that a spacecraft launched in 1977 can be fixed remotely from Earth." ― Brian Cox

            L 1 Reply Last reply
            0
            • Kornfeld Eliyahu PeterK Kornfeld Eliyahu Peter

              Better add 1 year and not 365 day...

              I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Does it account for me joining the company on the 29th februari?

              Edge case from Hell :suss: If you can't read my code, try converting it here[^]

              Kornfeld Eliyahu PeterK 1 Reply Last reply
              0
              • L Lost User

                Does it account for me joining the company on the 29th februari?

                Edge case from Hell :suss: If you can't read my code, try converting it here[^]

                Kornfeld Eliyahu PeterK Offline
                Kornfeld Eliyahu PeterK Offline
                Kornfeld Eliyahu Peter
                wrote on last edited by
                #7

                That does not matter to SQL - it has the requested knowledge to handle the 29th of February... In fact if you are working with 365 days you have to know when to add 365 or 366 to land on the right date - otherwise you will always get 28 of February. If you work with year you will move between 28 and 29 as it proper to the year...

                I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)

                "It never ceases to amaze me that a spacecraft launched in 1977 can be fixed remotely from Earth." ― Brian Cox

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups