sql case

WITH buy_fruit AS
 (SELECT 'Sophia Liu' as name,
  
  9 as price ,'apple' as fruit
  UNION ALL SELECT 'Lisa Stelzner',  5,'pear'
  UNION ALL SELECT 'Nikki Leith',  3  ,'banana'
  UNION ALL SELECT 'Lauren Matthews', 11,'grape'
  
  UNION ALL SELECT 'Lisa Stelzner',  20,'kiwi'
  UNION ALL SELECT 'Nikki Leith',  12  ,'orange'
  
  UNION ALL SELECT 'Lisa Stelzner',  2,'melon'
  
  UNION ALL SELECT 'Lauren Matthews', 100,'cherry'

 )
 
 
  
SELECT name, price, fruit ,
CASE
    WHEN price < 20 THEN 'the fruit is cheap'
    WHEN price<=50 THEN  'a little expansive'
    ELSE 'too expansive'
END AS comment
FROM buy_fruit ;
 
namepricefruitcomment
Sophia Liu9applethe fruit is cheap
Lisa Stelzner5pearthe fruit is cheap
Nikki Leith3bananathe fruit is cheap
Lauren Matthews11grapethe fruit is cheap
Lisa Stelzner20kiwia little expansive
Nikki Leith12orangethe fruit is cheap
Lisa Stelzner2melonthe fruit is cheap
Lauren Matthews100cherrytoo expansive
posted @ 2022-08-19 22:50  luoganttcc  阅读(13)  评论(0)    收藏  举报