SQL:
type(字段名)     
一年级
六年级
一年级
四年级
五年级
五年级
六年级
三年级
一年级
二年级
三年级
五年级
一年级
我想统计出 1年级出现了多少次     怎么统计呢?

解决方案 »

  1.   


    select count(1) from tb where type='一年级'
      

  2.   

    select count(*) from tb where type='一年级'
      

  3.   

    select count(*) from tb where type='一年级'
      

  4.   


    select type,count(1) from tb where type='一年级'
    group by type
      

  5.   

    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
      

  6.   


    select type,count(1) from tb
    group by type
      

  7.   

    select type,count(1) from tb
    group by type
      

  8.   


    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 行受影响)
    */
      

  9.   


    select type,count(1) from tb group by type
      

  10.   


    select count(1) from tb group by type
      

  11.   


    select type,count(*) from tb
    group by type
      

  12.   


    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
      

  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='一年级'