我认为 '.... similiar员工......' 由ID来定义,而这可能会给你一个提示:
Insert Into Payroll
Select id,period,paidDays,hourlyRate,hoursworked, overtime,overtimePay,
undertime,undertimePay,sss,philHealth,pagibig,OtherDeductions,
tax,grossPay,netPay
FROM (
select '$id' AS ID,'$period' AS period,'$paidDays' AS paidDays,
'$hourlyRate' AS hourlyRate, '$hoursworked' AS hoursworked,
'$overtime' AS overtime,'$overtimePay' AS overtimePay,
'$undertime' AS undertime,'undertimePay' AS undertimePay,
'$sss' AS sss,'$philHealth' AS philHealth,'$pagibig' AS pagibig,
'$OtherDeductions' AS OtherDeductions,'$tax' AS tax,
'$grossPay' AS grossPay,'$netPay' AS netPay, 0 AS JUM
UNION ALL
select id,period,paidDays,hourlyRate,hoursworked, overtime,
overtimePay, undertime,undertimePay,sss,philHealth,pagibig,
OtherDeductions,tax,grossPay,netPay, 1 AS JUM
from [YourTable]
Where [ID] = [EmployeeID]) AS T
GROUP BY id,period,paidDays,hourlyRate,hoursworked, overtime,
overtimePay, undertime,undertimePay,sss,philHealth,pagibig,
OtherDeductions,tax,grossPay,netPay
HAVING SUM(JUM) <0
你想要它被添加到数据库?或者你打算避免这种情况? – Sina
@Sina,我相信她想加入数据库,因为他想要“薪水历史”。有没有机会让这个专栏成为“唯一索引”? – Mustafa
Hi Sina!是的,它应该被添加到数据库中。 –