使用SUM的数据库子集


rs = s.executeQuery("SELECT Class1_predicted, Class2_predicted, Class3_predicted, Class_predicted"
+  SUM(PROFIT_LOSS) AS "Total Profit",
+ "FROM xxxxxx "
+ "WHERE CLASS1_PREDICTED = curr_class1_predicted, CLASS2_PREDICTED = curr_class2_predicted, CLASS3_PREDICTED = curr_class3_predicted, CLASS_PREDICTED = curr_class_predicted,"
+ "PROFIT_LOSS >= 0,"
+ "GROUP BY Class1_predicted, Class2_predicted, Class3_predicted,Class_predicted");
rs.next(); 
int recordCount = rs.getInt(1);
myConsole.getOut().println("Number of records in subset of table xxxxx where P/L >= 0: " + recordCount);

我在第二行得到一个错误的AS ?不知道如何纠正?

鲍勃M

你应该把整个查询放在一个字符串中。

看起来你并没有真正引用表达式:

+  SUM(PROFIT_LOSS) AS "Total Profit",

应该是这样的:

+  "SUM(PROFIT_LOSS) AS Total_Profit,"

最新更新