diff --git a/src/main/resources/sqlmapper/mappers/report/report.xml b/src/main/resources/sqlmapper/mappers/report/report.xml index 950b35e..4f6f56c 100644 --- a/src/main/resources/sqlmapper/mappers/report/report.xml +++ b/src/main/resources/sqlmapper/mappers/report/report.xml @@ -1230,19 +1230,14 @@ - SELECT - T.*, ROWNUM AS RN - FROM - ( - SELECT - A.NAME, - A.USERID AS go_id, - COALESCE(G.GO_GOAL1, 0) AS goGoal1, - COALESCE(G.GO_GOAL2, 0) AS goGoal2, - COALESCE(G.GO_GOAL3, 0) AS goGoal3, - COALESCE(G.GO_GOAL4, 0) AS goGoal4, - COALESCE(G.GO_TOTAL, 0) AS goTotal - FROM - (SELECT * FROM TAGENT WHERE PLACE1 = #{placeGroup}) A - LEFT OUTER JOIN - (SELECT DISTINCT * FROM RPT_AGENT_GOAL WHERE GO_MONTH = #{month} AND GO_YEAR = #{year}) G - ON G.GO_ID = A.USERID - ORDER BY - POSITION DESC, PLACE2, PLACE3, DUTIES, NAME - ) T + select (row_number () over()) AS rn, + t.* + from ( + select + a.name, + a.userid as go_id, + coalesce(b.go_goal1, 0) AS goGoal1, + coalesce(b.go_goal2, 0) AS goGoal2, + coalesce(b.go_goal3, 0) AS goGoal3, + coalesce(b.go_goal4, 0) AS goGoal4, + coalesce(b.go_total, 0) AS goTotal + from tagent a + left outer join rpt_agent_goal b on a.userid = b.go_id + and a.place1 = #{placeGroup} + and b.go_month = ${month} + and b.go_year = ${year} + order by position desc, place2, place3, duties, name + ) t - SELECT - ROWNUM AS RN, T.* - FROM - ( - SELECT - NAME, - COALESCE(GO_GOAL1, 0) AS GOAL1, COALESCE(GO_GOAL2, 0) AS GOAL2, COALESCE(GO_GOAL3, 0) AS GOAL3, COALESCE(GO_GOAL4, 0) AS GOAL4, - COALESCE(GO_GOAL1, 0) + COALESCE(GO_GOAL2, 0) + COALESCE(GO_GOAL3, 0) + COALESCE(GO_GOAL4, 0) AS GOAL_TOTAL, - (SELECT COUNT(*) FROM RPT_INFO WHERE IN_COMPLETE = 1 AND IN_USERID = A.USERID AND IN_INFO_YEAR = G.GO_YEAR AND IN_INFO_MONTH = G.GO_MONTH AND IN_CATEGORY4 = '01') AS RESULT1, - (SELECT COUNT(*) FROM RPT_INFO WHERE IN_COMPLETE = 1 AND IN_USERID = A.USERID AND IN_INFO_YEAR = G.GO_YEAR AND IN_INFO_MONTH = G.GO_MONTH AND IN_CATEGORY4 = '02') AS RESULT2, - (SELECT COUNT(*) FROM RPT_INFO WHERE IN_COMPLETE = 1 AND IN_USERID = A.USERID AND IN_INFO_YEAR = G.GO_YEAR AND IN_INFO_MONTH = G.GO_MONTH AND IN_CATEGORY4 IN ('03', '04', '05')) AS RESULT3, - (SELECT COUNT(*) FROM RPT_INFO WHERE IN_COMPLETE = 1 AND IN_USERID = A.USERID AND IN_INFO_YEAR = G.GO_YEAR AND IN_INFO_MONTH = G.GO_MONTH AND IN_CATEGORY4 = '06') AS RESULT4, - (SELECT COUNT(*) FROM RPT_INFO WHERE IN_COMPLETE = 1 AND IN_USERID = A.USERID AND IN_INFO_YEAR = G.GO_YEAR AND IN_INFO_MONTH = G.GO_MONTH) AS RESULT_TOTAL - FROM - (SELECT * FROM TAGENT WHERE PLACE1 = #{placeGroup}) A - LEFT OUTER JOIN - (SELECT DISTINCT * FROM RPT_AGENT_GOAL WHERE GO_YEAR = #{year} AND GO_MONTH = #{month}) G - ON G.GO_ID = A.USERID - ORDER BY - POSITION DESC, PLACE2, PLACE3, DUTIES, NAME - ) T + select (row_number () over()) AS rn, + t.* + from ( + select a.name, + a.userid as go_id, + coalesce(b.go_goal1, 0) AS goal1, + coalesce(b.go_goal2, 0) AS goal2, + coalesce(b.go_goal3, 0) AS goal3, + coalesce(b.go_goal4, 0) AS goal4, + coalesce(b.go_total, 0) AS goal_total, + coalesce(c.result1, 0) as result1, + coalesce(c.result2, 0) as result2, + coalesce(c.result3, 0) as result3, + coalesce(c.result4, 0) as result4, + coalesce(c.result_total, 0) as result_total + from tagent a + left outer join rpt_agent_goal b + on a.place1 = #{placeGroup} and b.go_year = ${year} and b.go_month = ${month} and a.userid = b.go_id + left outer join ( + select in_userid, + count(1) filter (where in_category4 = '01') as result1, + count(1) filter (where in_category4 = '02') as result2, + count(1) filter (where in_category4 in ('03', '04', '05')) as result3, + count(1) filter (where in_category4 = '06') as result4, + count(1) as result_total + from rpt_info + where in_complete = '1' + and in_place_code = #{placeGroup} + and in_info_year = ${year} + and in_info_month = ${month} + group by in_userid + ) c on c.in_userid = a.userid + order by position desc, place2, place3, duties, name + ) t