我刚开始使用nutz,在用自定义sql的时候,最后执行Sql的时候,nutz抛异常,查看异常信息,毫无头绪,找不到什么原因,原语句拷贝到navicat中可以完美运行,用nutz就会异常,还希望大神可以帮忙解决一下,感激不尽。
以下为JAVA代码:
Sql sql = Sqls.create("SELECT A.STAT_MO, A.usr_cnt, A.fluct, A.branch_cnt, b.cmcc_cty_nam, B.usr_cnt, CAST(B.usr_cnt AS DECIMAL(5, 2)) / A.total_usr_cnt AS usr_rt FROM ( SELECT A.STAT_MO, SUM(A.usr_cnt) AS usr_cnt, ( cast( SUM(A.usr_cnt) AS DECIMAL (16, 2)) - cast( SUM(A.last_usr_cnt) AS DECIMAL (16, 2))) / SUM(A.last_usr_cnt) AS fluct, COUNT(DISTINCT A.cmcc_branch_cd) AS branch_cnt, sum(total_usr_cnt) AS total_usr_cnt FROM $tableName A WHERE STAT_MO = $statMo GROUP BY A.STAT_MO ) A JOIN ( SELECT A.STAT_MO, a.cmcc_cty_nam, a.usr_cnt FROM $tableName A JOIN ( SELECT a.STAT_MO, a.CMCC_BRANCH_CD, count(*) AS RNK FROM $tableName a, $tableName b WHERE a.usr_cnt <= b.usr_cnt AND a.STAT_MO = $statMo AND b.STAT_MO = $statMo GROUP BY a.STAT_MO, a.CMCC_BRANCH_CD ) B ON A.STAT_MO = B.STAT_MO AND B.RNK = 1 AND A.CMCC_BRANCH_CD = B.CMCC_BRANCH_CD WHERE A.STAT_MO = $statMo ) b ON a.stat_mo = b.stat_mo");
String tableName = "";
if (Constant.TIME_ILLEGAL.equals(wgType)){
tableName = "TM_AUDIT_HOMEBRB_HALFDAY_RPT_M";
}else if (Constant.FLUX_ILLEGAL.equals(wgType)){
tableName = "TM_AUDIT_HOMEBRB_THIRTYM_RPT_M";
}else{
tableName = "TM_AUDIT_HOMEBRB_HALFTHIRTY_RPT_M";
}
sql.vars().set("statMo", statMo);
sql.vars().set("tableName", tableName);
sql.setCallback(Sqls.callback.records());
try {
this.getDao().execute(sql);
}catch (Exception e){
System.out.println(e.getMessage());
}
return sql.getList(Record.class);
以下为打印出的异常:
!Nutz SQL Error: 'SELECT A.STAT_MO, A.usr_cnt, A.fluct, A.branch_cnt, b.cmcc_cty_nam, B.usr_cnt, CAST(B.usr_cnt AS DECIMAL(5, 2)) / A.total_usr_cnt AS usr_rt FROM ( SELECT A.STAT_MO, SUM(A.usr_cnt) AS usr_cnt, ( cast( SUM(A.usr_cnt) AS DECIMAL (16, 2)) - cast( SUM(A.last_usr_cnt) AS DECIMAL (16, 2))) / SUM(A.last_usr_cnt) AS fluct, COUNT(DISTINCT A.cmcc_branch_cd) AS branch_cnt, sum(total_usr_cnt) AS total_usr_cnt FROM TM_AUDIT_HOMEBRB_HALFDAY_RPT_M A WHERE STAT_MO = 201710 GROUP BY A.STAT_MO ) A JOIN ( SELECT A.STAT_MO, a.cmcc_cty_nam, a.usr_cnt FROM TM_AUDIT_HOMEBRB_HALFDAY_RPT_M A JOIN ( SELECT a.STAT_MO, a.CMCC_BRANCH_CD, count(*) AS RNK FROM TM_AUDIT_HOMEBRB_HALFDAY_RPT_M a, TM_AUDIT_HOMEBRB_HALFDAY_RPT_M b WHERE a.usr_cnt <= b.usr_cnt AND a.STAT_MO = 201710 AND b.STAT_MO = 201710 GROUP BY a.STAT_MO, a.CMCC_BRANCH_CD ) B ON A.STAT_MO = B.STAT_MO AND B.RNK = 1 AND A.CMCC_BRANCH_CD = B.CMCC_BRANCH_CD WHERE A.STAT_MO = 201710 ) b ON a.stat_mo = b.stat_mo'
PreparedStatement:
'SELECT A.STAT_MO, A.usr_cnt, A.fluct, A.branch_cnt, b.cmcc_cty_nam, B.usr_cnt, CAST(B.usr_cnt AS DECIMAL(5, 2)) / A.total_usr_cnt AS usr_rt FROM ( SELECT A.STAT_MO, SUM(A.usr_cnt) AS usr_cnt, ( cast( SUM(A.usr_cnt) AS DECIMAL (16, 2)) - cast( SUM(A.last_usr_cnt) AS DECIMAL (16, 2))) / SUM(A.last_usr_cnt) AS fluct, COUNT(DISTINCT A.cmcc_branch_cd) AS branch_cnt, sum(total_usr_cnt) AS total_usr_cnt FROM TM_AUDIT_HOMEBRB_HALFDAY_RPT_M A WHERE STAT_MO = 201710 GROUP BY A.STAT_MO ) A JOIN ( SELECT A.STAT_MO, a.cmcc_cty_nam, a.usr_cnt FROM TM_AUDIT_HOMEBRB_HALFDAY_RPT_M A JOIN ( SELECT a.STAT_MO, a.CMCC_BRANCH_CD, count(*) AS RNK FROM TM_AUDIT_HOMEBRB_HALFDAY_RPT_M a, TM_AUDIT_HOMEBRB_HALFDAY_RPT_M b WHERE a.usr_cnt <= b.usr_cnt AND a.STAT_MO = 201710 AND b.STAT_MO = 201710 GROUP BY a.STAT_MO, a.CMCC_BRANCH_CD ) B ON A.STAT_MO = B.STAT_MO AND B.RNK = 1 AND A.CMCC_BRANCH_CD = B.CMCC_BRANCH_CD WHERE A.STAT_MO = 201710 ) b ON a.stat_mo = b.stat_mo'
16:53:04,519 ERROR http-apr-8081-exec-1 controller.ExceptionController:77 - web 00004:
null