首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

求分组后,数据条数解决方法

2012-04-05 
求分组后,数据条数select afrom tgroup by a求查询出来的记录条数[解决办法]SQL codeselect a,count(*)条

求分组后,数据条数
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*/ 

热点排行