日期:2014-05-18 浏览次数:20551 次
if object_id('[AA]') is not null drop table [AA]
create table [AA]([ID] int,[Type] int)
insert [AA]
select 1,1 union all
select 2,2 union all
select 3,2 union all
select 4,2 union all
select 5,1 union all
select 6,2 union all
select 7,1 union all
select 8,2 union all
select 9,1 union all
select 10,2
select [Type],COUNT(distinct [ID]) as counts from AA group by [Type]
/*
Type counts
1 4
2 6
*/
------解决方案--------------------
select type , count(*) num from aa group by type
select type , count(type) num from aa group by type
select type , count(1) num from aa group by type