Question

I am using SQL Server 2008 and navicat. I need to get Row Count in a table using SQL. The problem is that I am using Group By statement and my result is :

enter image description here

I need Sum of rcount value, the same like RowCount without Group By statement.

Thanks, in advance.

Was it helpful?

Solution

Assuming you want this as an additional column, you can do this using window functions:

select count(*) as rcount, goalarea,
       sum(count(*)) over () as TotalCount
from table t
group by goalarea;

If you want it as a separate row, I would use with rollup:

select count(*) as rcount, goalarea
from table t
group by goalarea with rollup;

(You can also use grouping sets, but I find with rollup easier for this simple problem.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top