首页 > 解决方案 > 将文本转换为数字以进行客户满意度调查

问题描述

我有客户满意度反馈,如好、差、优秀等,我想分配一个数值,如优秀 = 5、好 = 4、中性 = 2、不满意 = 0 然后按类别对值求和

这个查询我只需要以“选择”开头

按月分组 优秀 400 优秀 500

标签: sqlsql-server

解决方案


用例当

select sum(case when satisfaction ='Excellent' then 5 
            when satisfaction ='Good' then 4
            when satisfaction ='Neutral' then 2
             when satisfaction ='Dissatisfied' then 0 end) as satisfaction_val
,category from table_name group by category

推荐阅读