Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String queryStr = "select rtime, (case " + timeGroup + " else '' end) period,\n" +
- "sum(transfers), sum(revenue), sum(distance), "+/*sum(no_bus), */"sum(cancel_user), sum(cancel_driver), sum(idle) from (\n" +
- "select coalesce(t1.period, t2.period) period, coalesce(t1.rtime, t2.rtime) rtime, coalesce(transfers, 0) transfers,\n" +
- "coalesce(revenue, 0) revenue, coalesce(distance, 0) distance, coalesce(no_bus, 0) no_bus,\n" +
- "coalesce(cancel_user, 0) cancel_user, coalesce(cancel_driver, 0) cancel_driver,\n" +
- "coalesce ((\n" +
- "select round(sum(evduration)/60) from vehicle_history where pr_vehstatus = 2 and cur_vehstatus != 2 and\n" +
- "to_char(evdate, 'HH24')*60+to_char(evdate, 'MI') = coalesce(t1.period, t2.period) and\n" +
- "to_char(evdate, '" + groupingStr + "') = coalesce(t1.rtime, t2.rtime)\n" +
- "), 0) idle\n" +
- "from ( select to_char(rqtime, 'HH24')*60+to_char(rqtime, 'MI') period,\n" +
- "to_char(rqtime, '" + groupingStr + "') rtime,\n" +
- "sum(case when status=1 then 1 else null end) no_bus,\n" +
- "sum(case when status=98 then 1 else null end) cancel_user,\n" +
- "sum(case when status=99 then 1 else null end) cancel_driver\n" +
- "from req_history where rqtime between ?1 and ?2\n" +
- "group by to_char(rqtime, 'HH24')*60+to_char(rqtime, 'MI'), to_char(rqtime, '" + groupingStr + "')\n" +
- ") t1 full outer join (\n" +
- "select to_char(modified_at, 'HH24')*60+to_char(modified_at, 'MI') period,\n" +
- "to_char(modified_at, '" + groupingStr + "') rtime,\n" +
- "count(trnsf_id) transfers, sum(amount) revenue, sum(distance)/1000 distance\n" +
- "from transfers where modified_at between ?1 and ?2\n" +
- "group by to_char(modified_at, 'HH24')*60+to_char(modified_at, 'MI'), to_char(modified_at, '" + groupingStr + "')\n" +
- ") t2 on t1.period = t2.period and t1.rtime = t2.rtime) data\n" +
- "group by rtime, (case " + timeGroup + " else '' end) order by period asc";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement