2018年04月6日网站服务器迁移完成……

mysql操作查询结果case when then else end用法举例

mysql 苏 demo 1477℃ 0评论

举例1:

使用该查询,得出iFavoriteID,iFavUserType ,cUser,iArticleID,dFavoriteTime五个字段的值:

SELECT iFavoriteID,
CASE WHEN iFavUserType = 0 THEN ‘新闻管理员’
WHEN iFavUserType = 1 THEN ‘商家’
WHEN iFavUserType = 2 THEN ‘会员’
WHEN iFavUserType = 3 THEN ‘未注册’
WHEN iFavUserType = 4 then ‘匿名’
END AS iFavUserType, cUser, iArticleID,
CONVERT(nvarchar(100), dFavoriteTime, 111) AS dFavoriteTime FROM dig_favorite

举例2:

SELECT CASE WHEN `MEMBERTYPE` =1
THEN ‘参赛队员’
ELSE ‘指导老师’
END FROM `tab_sign_member`
WHERE 1

打赏

转载请注明:苏demo的别样人生 » mysql操作查询结果case when then else end用法举例

   如果本篇文章对您有帮助,欢迎向博主进行赞助,赞助时请写上您的用户名。
支付宝直接捐助帐号oracle_lee@qq.com 感谢支持!
喜欢 (0)or分享 (0)
发表我的评论
取消评论
表情