select strID, Sum(intR1Valid) as sumV1,Sum(intR1Total) as sumT1,sngR1Rate=(case when Sum(intR1Total) is null then null else Sum(intR1Valid)/Sum(intR1Total) end) from tbReportLog Group by strID order by strID
搞错了, select strID, Sum(intR1Valid) as sumV1,Sum(intR1Total) as sumT1,sngR1Rate=(case when isnull(Sum(intR1Total),0)=0 then null else Sum(intR1Valid)/Sum(intR1Total) end) from tbReportLog Group by strID order by strID
select sumV1/nullif(sumT1 ,0),sumT1時就返回null
select strID, Sum(intR1Valid) as sumV1,Sum(intR1Total) as sumT1,sngR1Rate=(case when isnull(Sum(intR1Total),0)=0 then null else Sum(intR1Valid)/Sum(intR1Total) end) from tbReportLog Group by strID order by strID
可以解决