MySQL case when 实例

<select id="selectByItem" resultType="com.shinho.dc3.dsfa.dto.SfaOrderRes" parameterType="com.shinho.dc3.dsfa.dto.SfaOrderSearch">
select a.orderid,a.ordercode,a.e_number,a.storeid,a.storecode,a.storename,a.bs_name,a.depment_id,
case a.order_type
when '100' then
'销售'
when '200' then
'退货'
else
''
end order_type,
a.amt,
a.row_count,
a.link_man,
a.link_tel,
a.addr,
a.pay_yu_amt,
a.pay_sh_amt,
a.pay_type,
a.gis,
a.remark,
a.did,
a.sfa_type,
a.deliverydate,
case a.DN_STATUS
when '100' then
'成功'
when '80' then
'失败'
when '10' then
'未创建'
else
''
end dn_status,
a.createtime,
a.insdt,
a.do_vbeln,
a.dn_vbeln,
a.do_msg,
a.dn_msg,
a.ca_vbeln,
a.ca_msg,
a.car_num,
a.do_status
from sfa_order a
where a.SFA_TYPE = '2'
<if test="pkeyWord != null and pkeyWord!=''" >
<bind name="pkeyWord" value="'%' + pkeyWord + '%'"/>
and
(UPPER (a.ordercode) like #{pkeyWord} or
UPPER (a.storecode) like #{pkeyWord} or
UPPER (a.storename) like #{pkeyWord} or
UPPER (a.do_vbeln) like #{pkeyWord} or
UPPER (a.dn_vbeln) like #{pkeyWord} or
UPPER (a.bs_name) like #{pkeyWord}
)
</if>
<if test="pStatus != null" >
and a.do_status= #{pStatus}
</if>
<if test="pDid != null" >
and a.did= #{pDid}
</if>
<if test="pDateStart != null" >
and a.insdt &gt;= pDateStart
</if>
<if test="pDateEnd != null" >
and a.insdt &lt;= pDateEnd
</if>
order by a.insdt desc
</select>

猜你喜欢

转载自www.cnblogs.com/pan-my/p/10758025.html