如何在sql server 2008中的同一个表中使用count和Group By with Self join?

时间:2013-10-28 11:06:08

标签: sql sql-server-2008 aggregate-functions

我有一个包含st_nameid列的表格。我需要计算st_name和按st_name分组。我该怎么做?

1 个答案:

答案 0 :(得分:0)

select st_name, 
       count(*) as grp_cnt,
       (select count(distinct st_name) from your_table) as st_cnt
from your_table
group by st_name