我有一个Employee表,我想根据加入DOJ
列的日期更新所有员工的体验列。
+----+---------+------------+-------------+------------+
| Id | name | DOJ | Designation | Experience |
+----+---------+------------+-------------+------------+
| 1 | Krishna | 14/01/2012 | Developer | |
| 2 | Rahim | 14/01/2013 | Developer | |
| 3 | Ram | 14/01/2014 | Developer | |
| 4 | Shyam | 14/01/2015 | Developer | |
| 5 | Ashok | 14/01/2016 | Developer | |
+----+---------+------------+-------------+------------+
答案 0 :(得分:0)
UPDATE test SET Experience = floor(datediff(curdate(),DOJ) / 365)
经验以月计算,
UPDATE test SET Experience = 12 * (YEAR(Curdate()) - YEAR(DOJ)) + (MONTH(curdate()) - MONTH(DOJ))