码迷,mamicode.com
首页 > 数据库 > 详细

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

时间:2015-08-14 19:43:54      阅读:150      评论:0      收藏: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


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

标签:

原文地址:http://my.oschina.net/u/2284972/blog/492540

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!