0
我想选择一个表的一个子集的字段的记录数量和金额子集 -
然后我要计数的记录数在这个子集
最后得到一个特定领域
我的代码的总和如下: -
// get the subset of records in the XXXXXX table
ps = conn.prepareStatement("SELECT Field1, Field2, Field3 FROM XXXXXXX "
+ "WHERE Field1 = ? AND Field2 = ? AND Field3 = ? "
+ "GROUP BY Field1, Field2, Field3");
ps.setString(1, variable1);
ps.setString(2, variable2);
ps.setString(3, variable3);
rs = ps.executeQuery();
int recordCount1 = 0;
while (rs.next()) {
recordCount1 = recordCount1 + rs.getInt(1);
}
rs.close();
ps.close();
myConsole.getOut().println("Number of records in Subset1 of table
XXXXXXX: " + recordCount1);
// now split the subset into those records where P/L > 0
and those records where P/L <0
// positive P/L
ps = conn.prepareStatement("SELECT Field1, Field2, Field3 "
+ "SUM(PL) AS Total_Profit FROM XXXXXX "
+ "WHERE Field1 = ? AND Field2 = ? AND Field3 = ? "
+ "AND PL >= 0 "
+ "GROUP BY Field1, Field2, Field3");
ps.setString(1, variable1);
ps.setString(2, variable2);
ps.setString(3, variable3);
rs = ps.executeQuery();
int recordCount2a = 0;
while (rs.next()) {
recordCount2a = recordCount2a + rs.getInt(1);
}
myConsole.getOut().println("Number of records in Subset of table
XXXXXX where P/L >= 0: " + recordCount2a);
我得到子集中的记录数为零计数
代码中有哪些区域是不正确的?
的显示数量,我认为你应该修改你的问题做出明确你想查询什么。还请为您正在使用的语言(Java?)添加标签。 –