日期:2014-05-17  浏览次数:20706 次

帮忙解释一下这句话~~
Java code
        querysql
        .append("select o.orgid,date_format(o.orderdate,'%Y'),count(*),sum(case when o.finalamount!='0.00' then o.finalamount else o.contractamount end)" +
                "as totalmoney,sum(case when o.payamount is not NULL then o.payamount else '0.00' end) as paymoney," +
                " (sum(case when o.finalamount!='0.00' then o.finalamount else o.contractamount end)-sum(case when o.payamount is not NULL and (case when o.finalamount!='0.00' then o.finalamount else o.contractamount end)!='0.00' then o.payamount else '0.00' end)) " +
                "as nopaymoney  from htglview o where 1=1 and o.contractState in (5,8,9,10,11) ");


------解决方案--------------------
select o.orgid,查询 orgid
date_format(o.orderdate,'%Y'), 输出 orderdate 年的数字
count(*) 统计结果集
sum(case when o.finalamount!='0.00' then o.finalamount else o.contractamount end)" +
"as totalmoney 已经解释过累加规则了 以别名 totalmoney 输出结果
sum(case when o.payamount is not NULL then o.payamount else '0.00' end) as paymoney同理
sum(case when o.finalamount!='0.00' then o.finalamount else o.contractamount end)-sum(case when o.payamount is not NULL and (case when o.finalamount!='0.00' then o.finalamount else o.contractamount end)!='0.00' then o.payamount else '0.00' end)) " +
"as nopaymoney
nopaymoney 是把 里面2个SUM结果集想减 case when then 这个就不解释 同理
 from htglview o where 1=1 and o.contractState in (5,8,9,10,11) 这个我就不用解释了吧
------解决方案--------------------
你这能debug吧,断点设在这句下面,看看querysql的值,就是完整的SQL语句了。。。
复制到PLSQL里,格式化的功能。


探讨
引用:
晕啊,就一个SQL语句,这样看不明白,就把它格式化出来,发这么长,一看乱七八糟啊


不会格式化才问你们的。。。请教一下如何格式化。谢谢了