我有以下代码: -
ps = conn.prepareStatement("SELECT COUNT(*), SUM(PROFIT_LOSS) AS Total_Profit, Field1, "
+ "Field2,Field3,Field4, Field5,Field6, Field7, Field8 FROM xxxxxx "
+ "WHERE Field1 = ? AND Field2 = ? AND "
+ "Field3 = ? AND Field4 = ? "
+ "AND Field5 = ? AND Field6 = ? AND "
+ "Field7 = ? AND Field8 = ? "
+ "AND PROFIT_LOSS >= 0 "
+ "GROUP BY Field1, Field2, Field3, Field4, Field5, "
+ "Field6, Field7, Field8");
ps.setString(1, variable1);
ps.setString(2, variable2);
ps.setString(3, variable3);
ps.setString(4, variable4);
ps.setString(5, variable5);
ps.setString(6, variable6);
ps.setString(7, variable7);
ps.setString(8, variable8);
rs = ps.executeQuery();
int recordCount2a = 0;
Total_Profit = 0;
while (rs.next()) {
recordCount2a = recordCount2a + rs.getInt(1);
Total_Profit = Total_Profit + rs.getDouble(2);
}
rs.close();
myConsole.getOut().println("Number of records in subset of table
xxxxxx where P/L >= 0: " + recordCount2a);
myConsole.getOut().println("Profit in subset of table xxxxxx: " +
Total_Profit);
我的结果显示正确的记录数,但总利润为零 数据库在> 4,000条记录
中的每一条中都有一个P / L编号我做错了什么?