复制
收藏
提问
全网

select case SUBST_ID when 16000172 then '1陆丰' when 16000065 then '2海丰' when 16000002 then '3城区' when 16000280 then '4陆河' when 16001009 then '5政企' else '其他' end subst_name, DISC_CLASS, case DISC_CLASS when 1 then '纯新套餐' when 2 then '存量加装' when 3 then '存量变更' when 4 then '拆机销户' when 5 then '优惠到期' end disc_class_zh, sum(value02), count(distinct serv_id) from zone_sw.TB_TYKS_SCORE_INC_MTD_mon where SUM_DATE = '20240827' and PROD_ID2 IN ('1010', '1011', '1012', '1013', '1015') group by case SUBST_ID when 16000172 then '1陆丰' when 16000065 then '2海丰' when 16000002 then '3城区' when 16000280 then '4陆河' when 16001009 then '5政企' else '其他' end, DISC_CLASS order by subst_name, DISC_CLASS desc;

心爱捕手
1个月前
全网
文档
学术
百科
知识库
时间不限
自动

理解问题select case SUBST_ID when 16000172 then '1陆丰' when 16000065 then '2海丰' when 16000002 then '3城区' when 16000280 then '4陆河' when 16001009 then '5政企' else '其他' end subst_name, DISC_CLASS, case DISC_CLASS when 1 then '纯新套餐' when 2 then '存量加装' when 3 then '存量变更' when 4 then '拆机销户' when 5 then '优惠到期' end disc_class_zh, sum(value02), count(distinct serv_id) from zone_sw.TB_TYKS_SCORE_INC_MTD_mon where SUM_DATE = '20240827' and PROD_ID2 IN ('1010', '1011', '1012', '1013', '1015') group by case SUBST_ID when 16000172 then '1陆丰' when 16000065 then '2海丰' when 16000002 then '3城区' when 16000280 then '4陆河' when 16001009 then '5政企' else '其他' end, DISC_CLASS order by subst_name, DISC_CLASS desc;

已完成理解select case SUBST_ID when 16000172 then '1陆丰' when 16000065 then '2海丰' when 16000002 then '3城区' when 16000280 then '4陆河' when 16001009 then '5政企' else '其他' end subst_name, DISC_CLASS, case DISC_CLASS when 1 then '纯新套餐' when 2 then '存量加装' when 3 then '存量变更' when 4 then '拆机销户' when 5 then '优惠到期' end disc_class_zh, sum(value02), count(distinct serv_id) from zone_sw.TB_TYKS_SCORE_INC_MTD_mon where SUM_DATE = '20240827' and PROD_ID2 IN ('1010', '1011', '1012', '1013', '1015') group by case SUBST_ID when 16000172 then '1陆丰' when 16000065 then '2海丰' when 16000002 then '3城区' when 16000280 then '4陆河' when 16001009 then '5政企' else '其他' end, DISC_CLASS order by subst_name, DISC_CLASS desc;

展开阅读网页

MySQL中的CASE WHEN语句用于根据条件返回不同的值。1

🔍语法解析

  • SUBST_ID条件:根据SUBST_ID的不同值返回对应的字符串。1
  • DISC_CLASS条件:根据DISC_CLASS的不同值返回对应的字符串。1

📊应用场景

  • 数据分类:将SUBST_IDDISC_CLASS进行分类,并进行聚合计算。1
  • 动态分组:根据SUBST_ID的值动态分组,并按DISC_CLASS降序排列。1
更专业一些
转笔记
专业
select case SUBST_ID when 16000172 then '1陆丰' when 16000065 then '2海丰' when 16000002 then '3城区' when 16000280 then '4陆河' when 16001009 then '5政企' else '其他' end subst_name, DISC_CLASS, case DISC_CLASS when 1 then '纯新套餐' when 2 then '存量加装' when 3 then '存量变更' when 4 then '拆机销户' when 5 then '优惠到期' end disc_class_zh, sum(value02), count(distinct serv_id) from zone_sw.TB_TYKS_SCORE_INC_MTD_mon where SUM_DATE = '20240827' and PROD_ID2 IN ('1010', '1011', '1012', '1013', '1015') group by case SUBST_ID when 16000172 then '1陆丰' when 16000065 then '2海丰' when 16000002 then '3城区' when 16000280 then '4陆河' when 16001009 then '5政企' else '其他' end, DISC_CLASS order by subst_name, DISC_CLASS desc;
知识树
select case SUBST_ID when 16000172 then '1陆丰' when 16000065 then '2海丰' when 16000002 then '3城区' when 16000280 then '4陆河' when 16001009 then '5政企' else '其他' end subst_name, DISC_CLASS, case DISC_CLASS when 1 then '纯新套餐' when 2 then '存量加装' when 3 then '存量变更' when 4 then '拆机销户' when 5 then '优惠到期' end disc_class_zh, sum(value02), count(distinct serv_id) from zone_sw.TB_TYKS_SCORE_INC_MTD_mon where SUM_DATE = '20240827' and PROD_ID2 IN ('1010', '1011', '1012', '1013', '1015') group by case SUBST_ID when 16000172 then '1陆丰' when 16000065 then '2海丰' when 16000002 then '3城区' when 16000280 then '4陆河' when 16001009 then '5政企' else '其他' end, DISC_CLASS order by subst_name, DISC_CLASS desc;
MySQL中的CASE语句有哪些应用场景?
如何在MySQL中使用CASE语句进行数据分类?
MySQL中的CASE语句与IF-ELSE语句有何区别?

以上内容由AI搜集生成,仅供参考

在线客服