mysql操作查詢結果case when then用法舉例

來源:互聯網
上載者:User

標籤:style   color   使用   art   re   c   

舉例1:

使用該查詢,得出iFavoriteID,iFavUserType ,cUser,iArticleID,dFavoriteTime五個欄位的值:

SELECT iFavoriteID,
CASE WHEN iFavUserType = 0 THEN ‘新聞管理員‘
WHEN iFavUserType = 1 THEN ‘商家‘
WHEN iFavUserType = 2 THEN ‘會員‘
END AS iFavUserType, cUser, iArticleID,CONVERT(nvarchar(100), dFavoriteTime, 111) AS dFavoriteTime

FROM dig_favorite;

 

舉例2:

SELECT a.UNIT,a.NUM_PRICE,a.WEIGHT_PRICE,(case WHEN a.UNIT=‘1‘ then a.NUM_PRICE else a.WEIGHT_PRICE end) price
from i_gift_inventory a;

舉例3:

select name,birthday,
 case 
     when birthday>‘1983‘ then ‘yong‘
        when name=‘lee‘ then ‘handsome‘
        else ‘just so so ‘ end
from lee;

 

舉例4;


SELECT CASE 1 WHEN 1 THEN ‘one‘
         WHEN 2 THEN ‘two‘ ELSE ‘more‘ END;

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.