我在我的gae中执行以下查询并获得异常。
PersistenceManager pm = getPersistenceManager();
StringBuilder sb = new StringBuilder();
sb.append(" select date, vehicleCode, vehicleSubCode, colorCode, ");
sb.append(" SUM(CASE WHEN transactionType = 0 THEN count ELSE 0 END) stock, ");
sb.append(" SUM(CASE WHEN transactionType = 1 THEN count ELSE 0 END) sale, ");
sb.append(" SUM(CASE WHEN transactionType = 2 THEN count ELSE 0 END) transfer ");
sb.append(" from Stock as AggregatedStock ");
Query query = pm
.newQuery(sb.toString());
query.setFilter(" updatedByDealer == " + dealer);
query.setGrouping(" date, vehicleCode, vehicleSubCode, colorCode ");
query.setOrdering(" vehicleCode desc ");
query.declareImports("import com.sandeepapplabs.dms.Stock");
我得到的例外是
com.google.api.server.spi.SystemService invokeServiceMethod: ')' expected at character 57 in "date, vehicleCode, vehicleSubCode, colorCode, SUM(CASE WHEN transactionType = 0 THEN count ELSE 0 END) - SUM(CASE WHEN transactionType = 1 THEN count ELSE 0 END) - SUM(CASE WHEN transactionType = 2 THEN count ELSE 0 END)"
javax.jdo.JDOUserException: ')' expected at character 57 in "date, vehicleCode, vehicleSubCode, colorCode, SUM(CASE WHEN transactionType = 0 THEN count ELSE 0 END) - SUM(CASE WHEN transactionType = 1 THEN count ELSE 0 END) - SUM(CASE WHEN transactionType = 2 THEN count ELSE 0 END)"
at org.datanucleus.api.jdo.NucleusJDOHelper.getJDOExceptionForNucleusException(NucleusJDOHelper.java:519)
at org.datanucleus.api.jdo.JDOQuery.execute(JDOQuery.java:230)
at com.sandeepapplabs.dms.AggregatedStockEndpoint.listAggregatedStock(AggregatedStockEndpoint.java:56)
类似的查询在SQLFiddle
中工作正常