Code select A.PD_DEPT_ID, sum(A.PD_MA_TOTAL) as amount,sum(A.PD_PASS_AMOUNT) as passAmount, ---一般不用round因为去不掉后面多余的小数位。 --CASE WHEN sum(A.PD_PASS_AMOUNT)=0 THEN 100 ELSE round((sum(A.PD_PASS_AMOUNT)*1.00)/(sum(A.PD_MA_TOTAL)*1.00),3) END AS passPercent --那就用convert吧。 CASEWHENsum(A.PD_PASS_AMOUNT)=0THEN100ELSEconvert(decimal(15,2),(sum(A.PD_PASS_AMOUNT)*1.00)/(sum(A.PD_MA_TOTAL)*1.00)) ENDAS passPercent
from tb_produce_data AS A LEFTJOIN TB_MATERIEL AS B ON A.PD_RAW_MA_ID=B.MA_ID WHERE (A.PD_DATE BETWEEN'2009-07-04'AND'2009-08-01') AND MA_PRJ_ID='489' GROUPBY A.PD_DEPT_ID