select type,count(1) from tb where type='一年级' group by type
select type,count(1) from tb where type='一年级' group by type select type,sum(case type when '一年级' then 1 esle 0 end) from tb group by type
select type,count(1) from tb group by type
select type,count(1) from tb group by type
if object_id('tb','U') is not null drop table tb go create table tb ( id int identity(1,1), type varchar(10) ) go insert into tb select '一年级' union all select '六年级' union all select '一年级' union all select '四年级' union all select '五年级' union all select '五年级' union all select '六年级' union all select '三年级' union all select '一年级' union all select '二年级' union all select '三年级' union all select '五年级' union all select '一年级' go select count(*) from tb where type='一年级' /* ----------- 4(1 行受影响) */
select type,count(1) from tb group by type
select count(1) from tb group by type
select type,count(*) from tb group by type
Create table banji ( 班级 varchar(10) ) select * from banji insert into banji values('一年级') insert into banji values('二年级') insert into banji values('三年级') insert into banji values('一年级') insert into banji values('一年级') insert into banji values('四年级') insert into banji values('一年级') insert into banji values('一年级') insert into banji values('五年级') insert into banji values('一年级') insert into banji values('一年级') insert into banji values('六年级') insert into banji values('一年级') insert into banji values('三年级') insert into banji values('一年级') insert into banji values('四年级') insert into banji values('一年级') insert into banji values('二年级') insert into banji values('一年级') insert into banji values('三年级') insert into banji values('一年级') insert into banji values('六年级') insert into banji values('一年级') --统计各个班级 出现次数select 班级, count(case when 班级='一年级' then 1 else 0 end)as 一年级from banji group by 班级二年级 2 六年级 2 三年级 3 四年级 2 五年级 1 一年级 13
USE BSADDPERSON; create table #table ( trpe varchar(10) ); insert into #table values('一年级') insert into #table values('二年级') insert into #table values('三年级') insert into #table values('一年级') insert into #table values('一年级') insert into #table values('四年级') insert into #table values('一年级') insert into #table values('一年级') insert into #table values('五年级') insert into #table values('一年级') insert into #table values('一年级') insert into #table values('六年级') insert into #table values('一年级') insert into #table values('三年级') insert into #table values('一年级') insert into #table values('四年级') insert into #table values('一年级') insert into #table values('二年级') insert into #table values('一年级') insert into #table values('三年级') insert into #table values('一年级') insert into #table values('六年级') insert into #table values('一年级')select count(0) from #table where type='一年级'
select count(1) from tb where type='一年级'
select type,count(1) from tb where type='一年级'
group by type
select type,sum(case type when '一年级' then 1 esle 0 end) from tb group by type
select type,count(1) from tb
group by type
group by type
if object_id('tb','U') is not null
drop table tb
go
create table tb
(
id int identity(1,1),
type varchar(10)
)
go
insert into tb
select '一年级' union all
select '六年级' union all
select '一年级' union all
select '四年级' union all
select '五年级' union all
select '五年级' union all
select '六年级' union all
select '三年级' union all
select '一年级' union all
select '二年级' union all
select '三年级' union all
select '五年级' union all
select '一年级'
go
select count(*) from tb where type='一年级'
/*
-----------
4(1 行受影响)
*/
select type,count(1) from tb group by type
select count(1) from tb group by type
select type,count(*) from tb
group by type
Create table banji
(
班级 varchar(10)
)
select * from banji
insert into banji values('一年级')
insert into banji values('二年级')
insert into banji values('三年级')
insert into banji values('一年级')
insert into banji values('一年级')
insert into banji values('四年级')
insert into banji values('一年级')
insert into banji values('一年级')
insert into banji values('五年级')
insert into banji values('一年级')
insert into banji values('一年级')
insert into banji values('六年级')
insert into banji values('一年级')
insert into banji values('三年级')
insert into banji values('一年级')
insert into banji values('四年级')
insert into banji values('一年级')
insert into banji values('二年级')
insert into banji values('一年级')
insert into banji values('三年级')
insert into banji values('一年级')
insert into banji values('六年级')
insert into banji values('一年级')
--统计各个班级 出现次数select 班级,
count(case when 班级='一年级' then 1 else 0 end)as 一年级from banji group by 班级二年级 2
六年级 2
三年级 3
四年级 2
五年级 1
一年级 13
create table #table
(
trpe varchar(10)
);
insert into #table values('一年级')
insert into #table values('二年级')
insert into #table values('三年级')
insert into #table values('一年级')
insert into #table values('一年级')
insert into #table values('四年级')
insert into #table values('一年级')
insert into #table values('一年级')
insert into #table values('五年级')
insert into #table values('一年级')
insert into #table values('一年级')
insert into #table values('六年级')
insert into #table values('一年级')
insert into #table values('三年级')
insert into #table values('一年级')
insert into #table values('四年级')
insert into #table values('一年级')
insert into #table values('二年级')
insert into #table values('一年级')
insert into #table values('三年级')
insert into #table values('一年级')
insert into #table values('六年级')
insert into #table values('一年级')select count(0) from #table where type='一年级'