Skip to content
Advertisement

SQL Sum of Count Values

I have this query and I’d like to get a sum of the count values in the ‘membership count’ column. How can I get the sum of the count values?

select count(MAJOR_KEY) 'membership count', chapter
from Name
where MEMBER_RECORD = 1 and
(STATUS = 'I' or STATUS = 'SN')
group by CHAPTER
order by CHAPTER

enter image description here

Advertisement

Answer

If you want a last row with the sum then use GROUP BY ROLLUP:

select count(MAJOR_KEY) [membership count], chapter
from Name
where MEMBER_RECORD = 1 and (STATUS = 'I' or STATUS = 'SN')
group by ROLLUP(CHAPTER)
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement