sql case查询的使用

本文深入解析了一段SQL查询语句,该语句涉及了多个分支判断和复杂的字段转换,展示了如何在特定条件下筛选和处理数据。通过实例分析,详细解释了查询语句的工作原理和应用场景,旨在帮助读者理解和掌握复杂SQL查询技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

select a.branchcode,
       (case a.branchname
         when '全国' then
          '全国'
         when '广东' then
          '粤'
         when '湖南' then
          '湘'
         when '湖北' then
          '鄂'
         when '四川' then
          '川'
         when '山东' then
          '鲁'
         when '江苏' then
          '苏'
         when '重庆' then
          '渝'
         when '河北' then
          '冀'
         when '上海' then
          '沪'
         when '安徽' then
          '皖'
         when '天津' then
          '津'
         when '浙江' then
          '浙'
         when '北京' then
          '京'
         when '河南' then
          '豫'
         when '辽宁' then
          '辽'
         when '深圳' then
          '深'
         when '福建' then
          '闽'
         when '大连' then
          '粤'
         when '广东' then
          '粤'
         when '厦门' then
          '粤'
       end) branchname,
       (case branchname
         when '全国' then
          dayvalueprem_pre || '万'
         else
          dayvalueprem_pre || ''
       end) aaadayvalueprem_pre, --日预收
       a.monthvalueprem_pre, --月预收
       a.monthvalueprem, --月核保价保
       a.achievementrate, --月核保达成
       a.activeresource --人力
  from reportbroker a
 where a.reportdate = '2012-06-07'
   and a.reporttype in ('A01_0', 'A01_1')
   and a.branchname not in ('厦门', '大连')
 order by branchcode;
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值