数据表中有字段“标识”,其内容包含以下词语:语文、数学、物理、化学、英语等,请问如何查询出包含这些词语的记录分别有多少?如包含“语文”的、包含“数学”的各有多少条

解决方案 »

  1.   


    select 标识,count(*) cnt
    from tb
    group by 标识
      

  2.   

    select 标识,count(1) from table group by 标识 order by 标识
      

  3.   

    select count(*),标识 from tb group by 标识
      

  4.   


    --分组查询
    select 标识,count(*) cnt
    from tb where 标识='语文' or 标识='数学'
    group by 标识
      

  5.   

          select count(*) from tb where 标识 like'语文%'
      

  6.   

    select '语文',count(*)
    from tb
    where charindex('语文',标识)>0
      

  7.   


    use dbx;
    godeclare @t table(标识 varchar(100));
    insert into @t select '语文,数学,化学' union all
    select '数学,英语,物理' union all
    select '化学' union all
    select '英语,语文';select * from @t;declare @a table(id varchar(100));
    insert into @a select '语文' union all select '数学' union all select '物理' union all select '化学' union all select '英语';select a.id,COUNT(1) as ct from @a a join @t b on b.标识 like '%'+a.id+'%'
    group by a.id