mysql操作查询结果case when then用法举例
举例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;
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。