波总,请教下,你像这种类型的sql,如何在Jfinal中拼接好些,sql如下:
select dqbm,a.yybm, dqmc,yymc,ypid,ypmc,je,b.zje,a.yzys,round(je / b.zje * 100, 3) bl, :zt
from (select max(dqbm) dqbm,max(dqmc) dqmc,yybm,max(yymc)yymc,ypid,max(ypmc) ypmc,yzys,sum(sl),sum(je) je from ZY_DPZYLCDYSJK
where dpz_bz=1 and rq >= :rq1 and rq <= :rq2 and ((yybm = :yybm and :yybm<> '0')or (:yybm = '0' and 1 = 1))
and ((dqbm = :dqbm and :dqbm<> '0')or (:dqbm = '0' and 1 = 1)) and ((lx = :lx and :lx<> '2')or (:lx = '2' and 1 = 1))
group by yzys ,ypid,yybm) a ,
(select yzys,yybm,sum(je) zje from ZY_DPZYLCDYSJK
where rq >= :rq1 and rq <= :rq2 and ((yybm = :yybm and :yybm<> '0')or (:yybm = '0' and 1 = 1))
and ((dqbm = :dqbm and :dqbm<> '0')or (:dqbm = '0' and 1 = 1)) and ((lx = :lx and :lx<> '2')or (:lx = '2' and 1 = 1))
group by yzys ,yybm) b
where a.yzys=b.yzys and a.yybm=b.yybm
accountListSql = select * from account \
where accountId=? \
and age > 18
对于以上这类有很多行的 sql,放在外部文件就不存在拼接的问题,直接书写就好。
此外,有些 sql 可能需要动态生成有些变动的项目,此时可以用一下类似于 freemarker的模板来写点代码来生成动态部,最好是先建一个 FreemarkerKit 工具类