【发布时间】:2015-10-14 02:55:39
【问题描述】:
我目前遇到的问题是我想选择一列并对值求和。然后我想总结同一张表中的另一列。目标是取这两个相加的列并将它们相减以获得输出。我的用途是休假。每周,员工都会获得数小时的假期。然后,当它们被使用时,它们位于不同的列中。我需要算出他们可以使用的假期总数。 这就是我所拥有的:
try
{
//Getting Information FROM EMPLOYEE_TIME_LOG for Vacation
Statement vacationLogstmt = dbConn.createStatement();
ResultSet vacationLogSet = vacationLogstmt.executeQuery(
"(SELECT SUM(vacation_gained) FROM employee_time_log WHERE employee_id_number = " +userInputIdNumber + "), " +
"(SELECT SUM(vacation_used) FROM employee_time_log WHERE employee_id_number = " +userInputIdNumber + "), " +
"GROUP BY vacation_gained, vacation_used");
vacationLogSet.next();
String strVacationEarned = vacationLogSet.getString(1);
String strVacationUsed = vacationLogSet.getString(2);
Double vacationEarned = Double.parseDouble(strVacationEarned);
Double vacationUsed = Double.parseDouble(strVacationUsed);
Double totalVacation = (vacationEarned - vacationUsed);
String strTotalVacation =Double.toString(totalVacation);
txtVacationTotal.setText(strTotalVacation);
}
catch (SQLException e)
{
//throw new JboException(e);
System.err.println(e);
String connectionError = "Problem with the database, please contact MIS.";
JOptionPane.showMessageDialog(new JFrame(), connectionError, "Database Error",JOptionPane.ERROR_MESSAGE);
txtUserSignIn.setText("");
txtUserSignIn.requestFocus();
}
我收到一个错误: java.sql.SQLSyntaxErrorException: ORA-00933: SQL 命令未正确结束
这甚至可以在一个结果集中完成吗?还是我只需要制作单独的结果集来做到这一点。
【问题讨论】:
标签: java oracle select resultset