use pubs
GO
select category =
Case type
   when 'popular_comp' then 'popular computing'
   when 'mod_cook' then 'modern cooking'
   when 'business' then 'Business'
when 'psychology' then 'Psychology '
when 'trad_cook' then 'trad_cook222'   else 'not yet categoried'
EndCAST(title as varchar(25)) as 'Shorterned title',price as Price
From titles
where price is not null
order by type,price
compute avg(price) by type

解决方案 »

  1.   

    select category =
    Case type
      when 'popular_comp' then 'popular computing'
      when 'mod_cook' then 'modern cooking'
      when 'business' then 'Business'
    when 'psychology' then 'Psychology '
    when 'trad_cook' then 'trad_cook222'  else 'not yet categoried'
    End
    ,
    CAST(title as varchar(25)) as 'Shorterned title',price as Price
    From titles
    where price is not null
    order by type,price
    compute avg(price) by type
      

  2.   

    use pubs
    GO
    select category =
    Case type
      when 'popular_comp' then 'popular computing'
      when 'mod_cook' then 'modern cooking'
      when 'business' then 'Business'
    when 'psychology' then 'Psychology '
    when 'trad_cook' then 'trad_cook222'  else 'not yet categoried'
    End
    ,
    CAST(title as varchar(25)) as 'Shorterned title'
    ,price as Price
    From titles
    where price is not null
    order by type,price
    compute avg(price) by type
    ----case when end后面少了一个逗号哦