问题
I have a single table with columns of st_name
and id
. I need to get the count of st_name
and Group by st_name
. How do I do this?
回答1:
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
来源:https://stackoverflow.com/questions/19633094/how-to-use-count-and-group-by-with-self-join-in-the-same-table-in-sql-server-200