The select a.o rder_quantity, a. d. eptname, a.s tatus The from (
Select count (mv. Id) order_quantity, hr. The deptname, 'exception' status The from hr_dept hr Left the join mrp_wo_v mv On mv. Manufact_Hr_dept_id=hr. Id And the mv. Plan_end_date & gt; Sysdate And substr (mv. Wo_date_str, 0, 4)='2017' And substr (mv. Wo_date_str, 5, 2)='12'
Group by hr. The deptname
Union all
Select count (mv. Id) order_quantity, hr. The deptname, 'normal' status The from hr_dept hr Left the join mrp_wo_v mv On mv. Manufact_Hr_dept_id=hr. Id And the mv. Plan_end_date & lt; Sysdate And substr (mv. Wo_date_str, 0, 4)='2017' And substr (mv. Wo_date_str, 5, 2)='12' Group by hr. The deptname
) a The order by a. d. eptname, a.s tatus;
Question: when the mv. Plan_end_date all CodePudding user response: The building Lord to the test data, and your expected results, facilitate everybody back to you
CodePudding user response:
1, when the mv. Plan_end_date all 2, put the and substr (mv) wo_date_str, 0, 4)='2017' and substr (mv) wo_date_str, 5, 2)='12' and mv. Instead wo_date_str like '201712%' will improve efficiency,