此sql查询未更新数据库,而是返回错误。有什么建议吗?
PreparedStatement ps10 = con.prepareStatement("UPDATE payroll_system.payslip SET hours_worked = (SELECT SUM(Hours) FROM payroll_system.monthly_timesheet WHERE employeeID=?) WHERE employeeID=?");
ps10.setString(1, employee_id);
ps10.setString(2, employee_id);
ps10.executeUpdate();
monthly_timesheet表:
payslip表:
答案 0 :(得分:0)
Insert don't have where clause
"INSERT INTO payroll_system.payslip(expense_claims)
WHERE employeeID=?
SELECT SUM(expense) FROM payroll_system.expense_master"
最终你在寻找更新?
或使用
"INSERT INTO payroll_system.payslip(expense_claims)
SELECT SUM(expense) FROM payroll_system.expense_mast"
更新
PreparedStatement ps9 = con.prepareStatement("UPDATE payroll_system.payslip
SET expense_claims = (SELECT SUM(Expense)
FROM payroll_system.expense_master
WHERE employeeID=?) WHERE employeeID=?");
ps9.setString(1, employee_id);
ps9.setString(2, employee_id);
ps9.executeUpdate();