1. Statistics of the number of orders created and completed in August by order type.
--According to the order type, the number of created and completed orders of various types in August select t.TYPEID,sum(t.create_num1) AS create_num,sum(t.create_done_num) AS create_done_num --t.create_num1: The column names referenced here are based on the column names of the first query from ( select two.TYPEID,count(two.WORKORDERID) AS create_num1,0 AS create_done_num from t_workorder two where two.CREATETIME >= to_date('2017-08','yyyy-MM') AND two.CREATETIME < add_months(to_date('2017-08','yyyy-MM'),1) group BY two.TYPEID --Execution result alone: --111105460,3,0 --111155044,1,0 union all select two.TYPEID,0 AS create_num2,count(two.WORKORDERID) AS create_done_num from t_workorder two where two.CREATETIME >= to_date('2017-08','yyyy-MM') AND two.CREATETIME < add_months(to_date('2017-08','yyyy-MM'),1) AND two.STATE = 10 group BY two.TYPEID --Execution result alone: --111105460,0,2 --union all results: --111105460,3,0 --111155044,1,0 --111105460,0,2 ) t group by t.TYPEID; --group result: --111105460,3,2 --111155044,1,0