mybatis 对string类型判断比较 group case when then 综合

[quote]

特别注意两点 一个是where 的用法
group的用法 
case when的用法

<if test='hasLoanApplicationFlag == "1"'>
这个对string的比较 是单引号 括起test后面的整串, 然后 == 然后双引号括起比较的字符串内容

[/quote]
[quote]

<select id="querySalesmanAndLoanInfoList" parameterType="com.zyd.orders.placeorder.model.SalesmanDO" 
resultType="com.zyd.orders.placeorder.model.SalesmanDO">


select T.salesmanId, T.salesmanCode, T.salesmanName, T.idNo, T.idType,T.phoneNo, T.channelId,T.registerDate, T.profession, T.email,
T.sumLoanAppCount, T.sumInProgressCount, T.sumFailLoanCount,T.sumReleaseCount,T.sumReleaseAmount ,T.channelName 
from 
(SELECT 
s.salesman_id as salesmanId,
s.salesman_code as salesmanCode,
s.salesman_name as salesmanName,
s.id_no as idNo, 
s.id_type as idType, 
s.phone_no as phoneNo, 
s.channel_id as channelId, 
s.register_date as registerDate, 
s.profession as profession,
s.email as email,
s.login_total_times,
count(case when ob.apply_status > 0 then ob.apply_status end) as sumLoanAppCount, 
count(case when ob.apply_status > 1 and ob.apply_status < 6 then ob.apply_status end) as sumInProgressCount,
count(case when ob.apply_status = 7 then ob.apply_status end) as sumFailLoanCount,
count(case when ob.release_status = 1 then ob.release_status end) as sumReleaseCount,
sum(case when ob.release_status = 1 then ob.release_money end) as sumReleaseAmount,
c.channel_name as channelName
from salesman s left join order_base ob 
on s.salesman_id = ob.user_id 
left join channel_vendor c
on s.channel_id = c.channel_id 
<where>
<if test="salesmanId != null and salesmanId != ''">
AND s.salesman_id = #{salesmanId}
</if>
<if test="phoneNo != null and phoneNo != ''">
AND s.phone_no = #{phoneNo}
</if>
<if test="password != null and password != ''">
AND s.password = #{password}
</if>
<if test="salesmanName != null and salesmanName != ''">
AND s.salesman_name = #{salesmanName}
</if>
<if test="idNo != null and idNo != ''">
AND s.id_no = #{idNo}
</if>
<if test="cardNo != null and cardNo != ''">
AND s.card_no = #{cardNo}
</if>
<if test="loanApplicationCode != null and loanApplicationCode != ''">
AND ob.id = #{loanApplicationCode}
</if>
<if test="registerBeginDate != null">
AND s.register_date >= #{registerBeginDate}
</if>
<if test="registerEndDate != null">
AND s.register_date <= #{registerEndDate}
</if>
</where>
group by s.salesman_id,s.salesman_code,s.salesman_name,s.id_no,s.id_type,s.phone_no,s.channel_id,s.register_date,s.profession,s.email,s.login_total_times 
) T
<where>
<if test='hasLoanApplicationFlag == "1"'>
AND T.sumLoanAppCount > 0
</if>
</where>

</select>

[/quote]

[quote]
select * from (
SELECT 
s.salesman_id as salesmanId,
s.salesman_name as salesmanName,
s.id_no as idNo, 
s.id_type as idType, 
s.phone_no as phoneNo, 
s.channel_id as channelId, 
s.register_date as registerDate, 
s.profession as profession,
s.email as email,
count(case when ob.apply_status = 7 then ob.apply_status else 0 end) as reject_count,
count(case when ob.apply_status > 1 and ob.apply_status < 6 then ob.apply_status else 0 end) as inprogress_count,
count(case when ob.apply_status > 0 then ob.apply_status else 0 end) as total_count,
count(case when ob.release_status = 1 then ob.apply_status else 0 end) as release_status,
sum(case when ob.release_status = 1 then ob.release_money else 0 end) as total_release_amt
from salesman s left join order_base ob
on s.salesman_id = ob.user_id 
where s.salesman_id = 1
group by s.salesman_id,s.salesman_name,s.id_no,s.id_type,s.phone_no,s.channel_id,s.register_date,s.profession,s.email


) t
[/quote]

转载于:https://www.cnblogs.com/zhuyeshen/p/11465648.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值