sql server - SQL - Percentage of one count by the other -
i trying percentage of first count sec count. in other words, want nbfirstcallresolutions / totalcases * 100.
select (select count([incident].incidentid) [incident],[caseresolution] [incident].incidentid = [caseresolution].regardingobjectid , [caseresolution].firstcallresolution = 1 , [incident].createdon >= @parameter_startdate , [incident].createdon <= dateadd(day,1,@parameter_enddate) ) nbfirstcallresolutions, (select count([incident].incidentid) [incident] [incident].createdon >= @parameter_startdate , [incident].createdon <= dateadd(day,1,@parameter_enddate) ) totalcases --select nbfirstcallresolutions / totalcases * 100.0
not sure how approach one...
your query should able consolidated this:
select sum(coalesce([caseresolution].firstcallresolution, 0) / count([incident].incidentid) * 100 [incident] left bring together [caseresolution] on [incident].incidentid = [caseresolution].regardingobjectid , [caseresolution].firstcallresolution = 1 [incident].createdon >= @parameter_startdate , [incident].createdon <= dateadd(day,1,@parameter_enddate
notice summed 1
value of firstcallresolution
, leaving nulls 0. equivalent of counting rows.
be sure check order of operations believe multiply occur first, followed divide.
sql sql-server count percentage
No comments:
Post a Comment