I have a situation where I want to sum the entire column, without grouping, but I also want the final output to be grouped for a particular country. For example, my input table looks something like this:

I want the output to sum columns at overall level and then create a new column with the sum individually for each country, so for UK, entire Headcount_UK, gets summed

I have tried using case and sum statement, but it is summing for that particular row and not the entire column.
Select country,
SUM(CASE When country='UK' THEN (Headcount_UK)
when country='ASIA' THEN (Headcount_Asia)
when country='USA' THEN (Headcount_USA)
when country='AFRICA' THEN (Headcount_Africa)
else 0 END) AS TOTAL
from students
group by country
Thank you
Two different methods below. The first uses a CTE with several UNIONed queries to get your totals; however, this calls the table many times. You'll probably want to use the 2nd method, which simply uses
conditional aggregation. But your DBMS may not support this because it's also incorporating awindows function(sum over).Query #1
Query #2
View on DB Fiddle