高分悬赏求助sql语句的写法

来源:百度知道 编辑:UC知道 时间:2024/07/07 01:33:51
我的数据库表字段为(编号,名称, 类别, 备注)
其中类别为国家级,市级,校级。必居其一。现在想做个统计的页面。即在一个gridview中显示出类别=国家级的记录数目,类别=市级的记录数目,类别=校级的记录数目。因为我只会用gridview显示数据。所以只能有一个sql语句。请问该sql语句该咋写。

select (select count(id) from table1 where 类别=国家级) as t1,(select count(id) from table1 where 类别=市级) as t2,(select count(id) from table1 where 类别=校级) as t3

select count(id) from 表名 where type='国家级'

select count(类别) as sum,类别 from table group by 类别

用report service的话,他里面可以设置展开