有一张表(tbcourse),如下
id    type    time
1     mat     2006-1-1
2     chm     2006-1-1
3     chm     2006-1-1
4     eng     2006-1-1
5     eng     2006-1-1一个sp,如下
select type,count(*) as sum from  tbcourse group by type
得到
mat   1
chm   2
eng   2
现在的问题是领导要求把mat表示成成‘数学’,chm表示成‘化学’,eng表示为‘英语’
该怎么办呢?麻烦各位指点一下

解决方案 »

  1.   

    select case type when 'mat' then '数学'
    when 'chm' then '化学'
    when 'eng' then '英语',sum from (select type,count(*) as sum from  tbcourse group by type) t
      

  2.   

    select (Case type When 'mat' Then '数学' When 'chm' Then '化学' When 'eng' Then '英语' End) As type, count(*) as sum from  tbcourse group by type
      

  3.   

    select case type when 'mat' then '数学'
    when 'chm' then '化学'
    when 'eng' then '英语' end,sum from (select type,count(*) as sum from  tbcourse group by type) t
      

  4.   

    create table test
    (
    type varchar(10),
    name varchar(10)
    )
    insert into test
    select 'chm','化学' union all
    select 'mat','数学' union all
    select 'eng','英语' 
    go
    select a.id,a.type,a.time,b.name from a inner join b on a.type = b.type
      

  5.   

    对了想问一下
    select case type when 'mat' then '数学'
    when 'chm' then '化学'
    when 'eng' then '英语' end,sum from (select type,count(*) as sum from  tbcourse group by type) t最后那个t什么意思?