Sql语句查询,使用CASE语句将英文转化中文输出

数据库字段如下( t_interaction表 ):


一般我们用sql语句取其类别的个数如下:

SELECT count(*) as count , type from t_interaction group by type

结果:


但是我们需要的是活动类型type直接显示为对应的中文输出(如下),否则我们又要在外层写判断语句很麻烦

QUIZ -转化-测试,

VOTE -转化- 投票问卷,

STORM -转化- 头脑风暴,

 QA -转化- 讨论答疑

扫描二维码关注公众号,回复: 1523203 查看本文章

那么我们就可以用case 语句(如下)

select count(*) as count,
case 
when(t.type='qa') then '讨论答疑' 
when(t.type='quiz') then '测试' 
when(t.type='storm') then '头脑风暴' 
when(t.type='vote') then '投票问卷' 

else 'x'  

end type  from t_interaction t group by type

查询结果(如下)



猜你喜欢

转载自blog.csdn.net/feidi7783/article/details/79699191