`
dannyhz
  • 浏览: 387573 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
文章分类
社区版块
存档分类
最新评论

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

 
阅读更多

引用


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

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


引用


<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 &gt; 0 then ob.apply_status  end) as sumLoanAppCount,
count(case when ob.apply_status &gt; 1 and ob.apply_status &lt; 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 &gt;= #{registerBeginDate}
          </if>
          <if test="registerEndDate != null">
           AND s.register_date &lt;= #{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 &gt; 0
          </if>
  </where>
 
    </select>



引用

            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
                
分享到:
评论

相关推荐

    Mybatis中执行String类型的自己拼写的sql,不执行配置文件中的sql

    本篇文章将详细探讨如何在MyBatis中执行String类型的自定义SQL,以及为何可能会选择不使用配置文件中的SQL。 首先,MyBatis的主要工作方式是通过Mapper接口和对应的XML配置文件来执行SQL。XML配置文件包含了SQL语句...

    mybatis 对clob类型转换

    在处理CLOB类型时,MyBatis需要将Java对象中的String或Reader类型数据转换为CLOB,以便存储到数据库中。 1. **CLOB类型数据的插入** 当你需要将一个字符串或者Reader对象插入到CLOB字段时,MyBatis默认可能无法...

    mybatis collection list string

    标题 "mybatis collection list string" 暗示了我们讨论的主题是关于MyBatis框架中与集合(List)和字符串(String)处理相关的问题。在MyBatis这个强大的持久层框架中,集合和字符串的使用非常常见,尤其是在进行数据库...

    解决mybatis使用char类型字段查询oracle数据库时结果返回null问题

    在使用mybatis框架对Oracle数据库进行查询操作时,如果使用char类型字段作为查询条件,可能会出现结果返回null的问题。这种情况下,需要对char类型字段进行特殊处理,以确保查询结果的正确性。 首先,需要了解...

    springmybatis

    MyBatis 目录(?)[-] mybatis实战教程mybatis in action之一开发环境搭建 mybatis实战教程mybatis in action之二以接口的方式编程 mybatis实战教程mybatis in action之三实现数据的增删改查 mybatis实战教程mybatis ...

    Mybatis 处理 CLOB、BLOB 类型数据

    MyBatis 提供了对 CLOB 和 BLOB 类型的内置支持,通过将 CLOB 类型映射到 Java 的 String 类型,BLOB 类型映射到 byte[] 类型。 在使用 MyBatis 时,需要在实体类中定义对应的字段类型,例如: ```java public ...

    MyBatis 参数类型为String时常见问题及解决方法

    在使用MyBatis框架时,有时会遇到与String类型参数相关的问题,尤其是在编写Mapper XML文件时。本文将详细讨论这些问题以及相应的解决方案。 首先,我们来看第一个问题:**参数为String时的插值问题**。在MyBatis中...

    StringBoot整合Mybatis案例源码

    本案例以"StringBoot整合Mybatis"为主题,旨在帮助开发者理解如何将这两个框架融合在一起,实现高效的数据访问。 首先,我们需要了解Spring Boot的核心特性。Spring Boot通过自动配置、起步依赖和内嵌Servlet容器,...

    3、mybatis类型的定义方式

    在MyBatis框架中,类型定义方式是其核心机制之一,它涉及到参数绑定、结果映射等关键功能。本文将详细解析MyBatis中的类型定义方式及其应用。 首先,MyBatis提供了多种类型处理器(TypeHandler),它们是MyBatis在...

    mybatis一对多的查询方法

    mybatis一对多的查询方法详解! mybatis一对多的查询方法详解! mybatis一对多的查询方法详解! mybatis一对多的查询方法详解!

    mybatis jar包

    MyBatis是一个优秀的Java持久层框架,它支持定制化SQL、存储过程以及高级映射。在Java开发中,MyBatis常被用来处理与数据库之间的交互,极大地简化了原本繁琐的手动SQL操作,提升了开发效率。 标题中的"mybatis jar...

    mybatis返回Integer

    在使用MyBatis进行数据操作时,我们经常会遇到关于返回值类型的困扰,特别是涉及到基本类型int和对象类型Integer之间的转换。标题"mybatis返回Integer"指的是在MyBatis的映射文件或者Mapper接口中,使用Integer作为...

    mybatis数据类型错误及解决方法

    在使用MyBatis框架进行Java开发时,我们经常会遇到数据类型错误的问题,这些错误主要源自于数据库字段类型与Java对象属性类型不匹配、SQL语句中的类型转换不当或MyBatis配置文件中的设置错误。本篇文章将深入探讨...

    Mybatis类型转换介绍 TypeHandler

    在Mybatis中,TypeHandler起着至关重要的作用,它是Mybatis处理Java类型与JDBC类型之间转换的桥梁。这篇博文将深入探讨Mybatis的TypeHandler机制及其在实际开发中的应用。 TypeHandler的主要职责是将Java类型的参数...

    MyBatis一对多映射

    在处理复杂的关联关系时,MyBatis的一对多映射机制显得尤为重要。一对多映射指的是一个父类实体对应多个子类实体的关系,例如一个学生可以有多个课程,一个部门可以有多名员工等。 一、一对多映射的基本概念 在...

    mybatis demo mybatis 实例

    3. 自动类型映射:MyBatis能自动将数据库结果集转换为Java对象,同时也支持自定义的类型处理器以处理特定类型的映射。 4. 缓存机制:MyBatis内置了本地缓存和二级缓存,能够提高数据读取效率,减少对数据库的访问。...

    mybatis入门实战之枚举类型

    本文将深入探讨在MyBatis中如何使用枚举类型,并通过实际的项目"mybatis入门实战之枚举类型"进行讲解。这个项目提供了一个简单的demo,非常适合初学者了解并实践MyBatis的TypeHandler机制。 首先,我们要明白枚举...

    mybatis中文文档

    MyBatis是一款优秀的持久层框架,它支持定制化SQL、存储过程以及高级映射,避免了几乎所有的JDBC代码和手动设置参数以及获取结果集的繁琐。MyBatis可以将配置和原生Map使用简单的XML或注解,将接口和Java的POJOs映射...

    spring boot 集成 mybatis

    在本文中,我们将深入探讨如何将Spring Boot与MyBatis集成,从而构建一个高效、简洁的SSM(Spring、SpringMVC、MyBatis)应用。Spring Boot以其自动化配置和开箱即用的特性,极大地简化了Java Web开发。而MyBatis...

    mybatis的中文api文档

    String resource = "org/mybatis/example/mybatis-config.xml"; InputStream inputStream = Resources.getResourceAsStream(resource); sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream); ...

Global site tag (gtag.js) - Google Analytics