create table tb (id int,typ numeric(10),name varchar(10))
Insert into tb
select '1','1','ww'
union all select '2','1','ss'
union all select '3','1','tt'
union all select '4','2','rr'
union all select '5','2','dd'
union all select '6','3','hh'
--刪除表
drop table tb
drop table tt
select id=identity(int,1,1),纪录数量=count(*) into tt from tb group by typ
select * from tt
--結果
id 纪录数量
-----------------------
1 3
2 2
3 1
create table tb (id int,typ numeric(10),name varchar(10))
Insert into tb
select '1','1','ww'
union all select '2','1','ss'
union all select '3','1','tt'
union all select '4','2','rr'
union all select '5','2','dd'
union all select '6','3','hh'
--刪除表
drop table tb
select id=sum(1),纪录数量=count(*) from tb group by typ
--結果
id 纪录数量
-----------------------
3 3
2 2
1 1