Reworded title: Calculating the experience an employee accumulates across multiple jobs
P粉212971745
P粉212971745 2023-09-04 21:03:55
0
1
505
<p>I have a table called employee experience with columns id, userId, startDate and endDate. </p> <p>I want to calculate the work experience of employees. Can anyone help provide code for mysql query or JPA specification? </p> <p>For example, for the following data: </p> <table class="s-table"> <thead> <tr> <th>id</th> <th>User ID</th> <th>Start Date</th> <th>End date</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>1</td> <td>2021-01-01</td> <td>2022-01-01</td> </tr> <tr> <td>2</td> <td>2</td> <td>2019-01-01</td> <td>2020-01-01</td> </tr> <tr> <td>3</td> <td>2</td> <td>2020-01-02</td> <td>2021-01-01</td> </tr> <tr> <td>4</td> <td>3</td> <td>2021-01-01</td> <td>2022-01-01</td> </tr> </tbody> </table> <p>The output should be: </p> <table class="s-table"> <thead> <tr> <th>User ID</th> <th>Experience</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>1</td> </tr> <tr> <td>2</td> <td>2</td> </tr> <tr> <td>3</td> <td>1</td> </tr> </tbody> </table></p>
P粉212971745
P粉212971745

reply all(1)
P粉486138196

Successfully accomplished this using the following code:

SELECT SUM(TIMESTAMPDIFF(YEAR, START_DATE, END_DATE)) AS experience,
          SOCIAL_PROFILE_ID
   FROM tableName
   GROUP BY SOCIAL_PROFILE_ID
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template