求分组后,数据条数
select a
from t
group by a
求查询出来的记录条数
[解决办法]
- SQL code
select a,count(*)条数from tgroup by a
[解决办法]
- SQL code
declare @t table (a int)insert into @tselect 1 union allselect 1 union allselect 2 union allselect 2 union allselect 3--分组后的结果 select a from @t group by a/*a-----------123*/--每组的条数select a,count(1) as cnt from @t group by a/*a cnt----------- -----------1 22 23 1*/--总条数select count(distinct a) as cnt from @t/*cnt-----------3*/