日期:2014-05-18 浏览次数:20638 次
select a,count(*)条数 from t group by a
------解决方案--------------------
declare @t table (a int)
insert into @t
select 1 union all
select 1 union all
select 2 union all
select 2 union all
select 3
--分组后的结果
select a from @t group by a
/*
a
-----------
1
2
3
*/
--每组的条数
select a,count(1) as cnt from @t group by a
/*
a cnt
----------- -----------
1 2
2 2
3 1
*/
--总条数
select count(distinct a) as cnt from @t
/*
cnt
-----------
3
*/