case基础应用

 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  'Traditional Cooking'
         ELSE  'Not yet categorized'
      END,
   CAST(title AS varchar(25)) AS  'Shortened Title' ,
   price AS Price
FROM titles
WHERE price IS NOT NULL
ORDER BY type, price
COMPUTE AVG(price) BY type

你可能感兴趣的:(case)