列表查询和分组统计字段其他类型

示例: 

--列表查询
--字段单选
<if test='byqrzgxwF != null and byqrzgxwF != "" and byqrzgxwF != "其他"'>
	AND a.byqrzgxw = #{byqrzgxwF}
</if>
<if test='byqrzgxwF != null and byqrzgxwF != "" and byqrzgxwF == "其他" '>
	AND decode(a.byqrzgxw,'本科',1,'硕士',2,'博士',3 ,0) = 0
</if>

--字段多选
<if test="lfsyF != null and lfsyF != '' and lfsyF !='其他'">
	AND a.lfsy LIKE '%'||#{lfsyF}||'%'
</if>
<if test="lfsyF != null and lfsyF != '' and lfsyF =='其他'">
	AND (a.lfsy like '%其他%' or a.lfsy is null
		or (a.lfsy not like '%授课%' and a.lfsy not like '%短期讲学%' 
            and a.lfsy not like '%合作研究%' and a.lfsy not like '%学术访问%'
			and a.lfsy not like '%工作访问%' and a.lfsy not like '%国际会议%' 
            and a.lfsy not like '%培训%' and a.lfsy not like '%其他%' 
            and a.lfsy is not null)
		)
</if>


--类型分组统计
--字段单选
SELECT dz,
		NVL(sum(decode(sfyc,'是',1,0)),0) as "是",
		NVL(sum(decode(sfyc,'否',1,0)),0) as "否",
		NVL(sum(decode(sfyc,'是',0,'否',0,'',1,1)),0) as "其他"
FROM LFJD 
GROUP BY dz;


--字段多选(字段两侧拼逗号防止出现教授与副教授重复被计算)
SELECT dz,
		NVL(sum(decode(sign(INSTR(','||sfyc||',',',是,')-1),1,1,0,1,0)),0) as "是",
		NVL(sum(decode(sign(INSTR(','||sfyc||',',',否,')-1),1,1,0,1,0)),0) as "否",
		NVL(sum(decode(sign(INSTR(','||sfyc||',',',其他,')-1),1,1,0,1,0)),0) +             
          NVL(sum(decode(sfyc,'',1)),0) + 
		  NVL(sum(decode(sign
                    (
                    INSTR(','||sfyc||',',',是,')+
                    INSTR(','||sfyc||',',',否,')+
                    INSTR(','||sfyc||',',',其他,')+
                    decode(sfyc,'',1,0)
                    ),0,1,0)
                 ),0) as "其他"
FROM LFJD 
GROUP BY dz;

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值