上面这张图如果前台给我传一个status=4的一个状态 我要把状态是4,5,7的数据返回去,这个sql应该怎么写 应该where后面的把
补充下问题啊 如果传1返回1的数据 传2返回2 的数据就是传4时不同
sql里的if判断应该怎么判断 后面还有好多判断条件的
select d.transferID,d.PatientName,d.Mobile,d.CreateDate,d.doctorName_from,d.doctorId_from,
d.Status,
d.doctorId_to,d.doctorName_to,d.HospitalId_to,d.HospitalName_to
from his_transfertreatmentrecord d
where 1=1
<if test="status == '4'">
and Status in ('4','5','7')
</if>
<!-- <if test="status!=null and status!='' and status!='4'">
and Status = #{status,jdbcType=VARCHAR}
</if> -->
<if test="doctorNameFrom!=null and doctorNameFrom!=''">
and doctorName_from like CONCAT('%',#{doctorNameFrom,jdbcType=VARCHAR},'%')
</if>
<if test="patientName!=null and patientName!=''">
and patientName like CONCAT('%',#{patientName,jdbcType=VARCHAR},'%')
</if>
<if test="userId!=null and userId!=''">
and (doctorId_from=#{userId} or doctorId_to=#{userId})
</if>
<if test="createDate!=null and createDate!='' || createDate1!=null and createDate1!=''">
and CreateDate between '${createDate}' and DATE_ADD('${createDate1}',interval 1 day)
</if>
order by d.createDate desc
limit #{start},#{rows};
这是我的原来的sql
sql的问题,请大神们帮忙啊
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
8条回答 默认 最新
- 疯狂的熊猫Npe 2018-11-22 09:14关注
可以尝试着把这个if用switch case的方式代替 ,
private int [] getStatus(int status){ String str = ""; switch(status){ case 1: str = "1"; break; case 4: str = "4,5,7" break; case 5: str = "5,7,8" break; } // 返回status数组 return str.split(","); } xml里面直接 where status in <foreach collection="status" item="status" open="(" separator="," close=")"> #{status} </foreach>
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用
悬赏问题
- ¥15 c程序不知道为什么得不到结果
- ¥40 复杂的限制性的商函数处理
- ¥15 程序不包含适用于入口点的静态Main方法
- ¥15 素材场景中光线烘焙后灯光失效
- ¥15 请教一下各位,为什么我这个没有实现模拟点击
- ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
- ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
- ¥20 有关区间dp的问题求解
- ¥15 多电路系统共用电源的串扰问题
- ¥15 slam rangenet++配置