select Convert(varchar(7),YearMonth,23)as A , SUM( CASE WHEN Minor = '1' THEN - Convert(int,Number1) WHEN Minor = '3' and [Audit] = 2 THEN - Convert(int,Number1) WHEN Minor = '2' THEN Convert(int,Number1) WHEN Minor = '4' THEN Convert(int,Number1) END ) from T_User_Commodity group by Convert(varchar(7),YearMonth,23)