当前位置:网站首页>Find the latest staff salary and the last staff salary changes

Find the latest staff salary and the last staff salary changes

2022-08-11 07:52:00 A little birds

There is such a demand to find the latest salary situation and the second latest salary situation of personnel, and then calculate an increase situation

The database used is mysql database

The form used is as follows:

Personnel list:listuser

Payroll:ry

sql display

Query the latest data according to time

SELECT a.id,a.dy_id,a.gz,max(a.time) from ry a GROUP BY dy_id

Query the second latest data according to time

SELECT a.id,a.dy_id,a.gz,a.time from ry a where a.id=( SELECT id from ry where a.dy_id=dy_id ORDER BY time LIMIT 1,1 )

Then you can perform a related query

原网站

版权声明
本文为[A little birds]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/223/202208110656269714.html