我認爲 '.... 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!是的,它應該被添加到數據庫中。 –