for (Record wd : wds) { String wdid = wd.getStr("wdid"); Integer sum = 0; for (Record xx : psyXuanxiangs) { String tmid = xx.getStr("tmid"); String daid = xx.getStr("daid"); try { Integer fen = Db.queryInt("select fen from psy_dwd where tmid=? and daid=? and wdid=?", tmid, daid, wdid); sum = sum + fen; } catch (Exception e) { } } wdfen.put(wdid, sum); } System.out.println(JsonKit.toJson(wdfen)); }
上面的代码中,有一条sql位于循环内部,造成系统非常缓慢,如果拿出来的话,用程序逻辑来写,比sql语法又多得多,同样也缓慢,不知道有什么样好的解决方案吗?