I am calculating a % completeness figure for a number of sites, with each site having a designated 'Base' figure. I've used the code below to work out each site's individual completeness but I'm struggling to get an overall sum of the 'Base' figure:
select isnull(Site,'Total') Site, max(base) Base,
round(count(submissionID)/max(base)*100,2) DataCompleteness
from PRIcache
left join hsite on hsite=site and hyear=2013
where network='sussex' and year(arvd)=2015
group by site with rollup
I've used max as I needed to include the field in an aggregate function but as result the total row displays the max base figure from all the sites instead of the sum of the base figures. For example:
Site 1 base=214
Site 2 base=114
Total base=214
Is there a way to add the base figure into my select statement so it will totalled up? Thanks.
SQL fiddle link with example: http://sqlfiddle.com/#!3/ddf38/1