caoweichen520 2018-11-22 09:03 采纳率: 0%
浏览 413
已采纳

sql的问题,请大神们帮忙啊

图片说明

            上面这张图如果前台给我传一个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
  • 写回答

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>
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(7条)

报告相同问题?

问题事件

  • 已采纳回答 9月22日

悬赏问题

  • ¥15 Matlab问题解答有两个问题
  • ¥50 Oracle Kubernetes服务器集群主节点无法访问,工作节点可以访问
  • ¥15 LCD12864中文显示
  • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决
  • ¥15 gsoap生成onvif框架
  • ¥15 有关sql server business intellige安装,包括SSDT、SSMS。
  • ¥15 stm32的can接口不能收发数据
  • ¥15 目标检测算法移植到arm开发板
  • ¥15 利用JD51设计温度报警系统
  • ¥15 快手联盟怎么快速的跑出建立模型