我需要帮助才能找到可能的解决方案。我坚持这个查询。
表1 - hs_hr_employee
表2 - ohrm_leave_entitlement
我需要加入这些表并获得加入日期并更新0.5添加。如果差异(当前dt-Dt。of Joining)> 10。
这是我的查询
UPDATE ohrm_leave_entitlement
SET no_of_days = no_of_days + 0.5
WHERE
(
ohrm_leave_entitlement.emp_number = hs_hr_employee.emp_number
AND
hs_hr_employee.joined_date < DATE_SUB( NOW(), INTERVAL 10 DAY)
AND
leave_type_id=2
)
但它不起作用..
答案 0 :(得分:2)
UPDATE ohrm_leave_entitlement a
INNER JOIN hs_hr_employee b
ON a.emp_number = b.emp_number
SET a.leave_type_id = a.leave_type_id + 0.5
WHERE DATEDIFF(NOW(), b.joined_date) > 10
答案 1 :(得分:0)
您可以尝试以下内容:
UPDATE ohrm_leave_entitlement , hs_hr_employee
SET ohrm_leave_entitlement.leave_type_id = ohrm_leave_entitlement.leave_type_id + 0.5
WHERE ohrm_leave_entitlement.emp_number = hs_hr_employee.emp_number
AND hs_hr_employee.joined_date < DATE_SUB( NOW(), INTERVAL 10 DAY)
答案 2 :(得分:0)
您可以使用:
UPDATE ohrm_leave_entitlement
SET leave_type_id = leave_type_id + 0.5
WHERE
ohrm_leave_entitlement.emp_number IN (SELECT hs_hr_employee.emp_number FROM hs_hr_employee
WHERE hs_hr_employee.joined_date < DATE_SUB( NOW(), INTERVAL 10 DAY))