<strong> StringBuilder sbud = new StringBuilder("select distinct tps.project_id id from t_project_stage tps"); sbud.append(" inner join t_stage ts on ts.id = tps.stage_id where "); sbud.append(" tps.last_modified is not null and tps.last_modified -1<to_date('%2$s', 'yyyy-MM-dd')"); // sbud.append(" and tps.last_modified < to_date('%3$s', 'yyyy-MM-dd')+1 and tps.overdue=0 group by tps.project_id having MAX(ts.order_no)=%1$s) tt2 on tt.id =tt2.id "); sbud.append(" and to_date('%3$s', 'yyyy-MM-dd') < <span style="color:#ff0000;">ADD_MONTHS</span>(tps.last_modified, 2) +1 and tps.overdue=0 and ts.order_no=%1$s) tt2 on tt.id =tt2.id "); builder.append(String.format(sbud.toString(),witchStage,firstDay,firstDay));</strong>
原文地址:http://blog.csdn.net/tannongchun/article/details/42152723