mysql select case语句吗
1个回答
展开全部
MySql数据库不支持select case语句,但是它支持功能类似的case when函数。下面是函数的有关语法和使用示例:
语法1
CASE WHEN expr1 THEN v1 [WHEN expr2 THEN v2...][ELSE vn] END
例句:
select id,grade,case when grade>60 then 'good' when grade=60 then 'pass'
else 'fail' end as level from t1;
返回
id grade level
001 90 good
002 50 fail
003 60 pass
004 null fail
语法2
CASE expr WHEN e1 THEN v1 [WHEN e2 THEN v2...][ELSE vn] END
例句:
select id,grade,case grade when 90 then 'good' when 60 then 'pass'
when 50 then 'fail' else 'no grade' end as level from t1;
返回
id grade level
001 90 good
002 50 fail
003 60 pass
004 null no grade
语法1
CASE WHEN expr1 THEN v1 [WHEN expr2 THEN v2...][ELSE vn] END
例句:
select id,grade,case when grade>60 then 'good' when grade=60 then 'pass'
else 'fail' end as level from t1;
返回
id grade level
001 90 good
002 50 fail
003 60 pass
004 null fail
语法2
CASE expr WHEN e1 THEN v1 [WHEN e2 THEN v2...][ELSE vn] END
例句:
select id,grade,case grade when 90 then 'good' when 60 then 'pass'
when 50 then 'fail' else 'no grade' end as level from t1;
返回
id grade level
001 90 good
002 50 fail
003 60 pass
004 null no grade
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询