• 复杂的sql语句 + having


    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE mapper
    PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
    "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    <!-- 命名空间的值为dao层接口的权限定名 -->
    <mapper namespace="com.bawei.dao.GdpDao" >

    <select id="findAll" resultMap="maps">
    select g.*,p.name as name,p.pnum as pnum,(g.industryIncome-g.industryInvest) as industryProfits,
    ((g.industryIncome-g.industryInvest)/g.industryIncome*100) as industryProfitsMargin,
    (g.agIncome-g.agInvest) as agProfits,
    ((g.agIncome-g.agInvest)/g.agIncome*100) as agProfitsMargin,
    (g.industryIncome/(g.industryIncome+g.agIncome)*100) as industryBiZhong
    from tb_gdp g LEFT JOIN tb_province p ON g.provinceId=p.id
    <where>
    <if test="provinceId!=null and provinceId!=0 ">
    and provinceId=#{provinceId}
    </if>
    <if test="pnumMin!=null ">
    and pnum &gt;= #{pnumMin}
    </if>
    <if test="pnumMax!=null ">
    and pnum &lt;= #{pnumMax}
    </if>
    <if test="profitsMin!=null ">
    and ((g.agIncome+g.industryIncome-g.agInvest-g.industryInvest)/(g.agIncome+g.industryIncome)*100) &gt;= #{profitsMin}
    </if>
    <if test="profitsMax!=null ">
    and ((g.agIncome+g.industryIncome-g.agInvest-g.industryInvest)/(g.agIncome+g.industryIncome)*100) &gt;= #{profitsMax}
    </if>
    <if test="industryInvestMin!=null ">
    and g.industryInvest &gt;= #{industryInvestMin}
    </if>
    <if test="industryInvestMax!=null ">
    and g.industryInvest &lt;= #{industryInvestMax}
    </if>
    <if test="agIncomeMin!=null ">
    and g.agIncome &gt;= #{agIncomeMin}
    </if>
    <if test="agIncomeMax!=null ">
    and g.agIncome &lt;= #{agIncomeMax}
    </if>
    <if test="monthMin!=null ">
    and g.month &gt;= #{monthMin}
    </if>
    <if test="monthMax!=null ">
    and g.month &lt;= #{monthMax}
    </if>
    </where>
    GROUP BY g.id
    <trim prefix="having" prefixOverrides="and" >
    <if test="yearMin!=null ">
    and SUM(g.agIncome+g.industryIncome) &gt;= #{yearMin}
    </if>
    <if test="yearMax!=null ">
    and SUM(g.agIncome+g.industryIncome) &lt;= #{yearMax}
    </if>
    </trim>
    </select>

    <resultMap type="Gdp" id="maps">
    <id property="id" column="id" />
    <result property="provinceId" column="provinceId" />
    <result property="month" column="month" />
    <result property="industryInvest" column="industryInvest" />
    <result property="industryIncome" column="industryIncome" />
    <result property="eConsumer" column="eConsumer" />
    <result property="agInvest" column="agInvest" />
    <result property="agIncome" column="agIncome" />

    <result property="industryProfits" column="industryProfits" />
    <result property="industryProfitsMargin" column="industryProfitsMargin" />
    <result property="agProfits" column="agProfits" />
    <result property="agProfitsMargin" column="agProfitsMargin" />
    <result property="industryBiZhong" column="industryBiZhong" />

    <!-- <association property="pro" javaType="Province">
    <id property="pid" column="pid" />
    <result property="name" column="name" />
    <result property="pnum" column="pnum" />
    </association> -->
    </resultMap>




    </mapper>

  • 相关阅读:
    Linux信号列表(zz)
    TCP状态转移图学习总结
    UNP学习笔记之四select和poll
    RSS2.0结构
    UNP学习笔记二简单的并发服务器(concurrent servers)
    js面向对象基础(zz)
    libevent introduction
    Linux下Makefile的automake生成全攻略(zz)
    UNP学习笔记之三POSIX Signal Handling
    关于网络编程(服务端)的一些笔记(zz)
  • 原文地址:https://www.cnblogs.com/liuzhaolong/p/12880517.html
Copyright © 2020-2023  润新知