首页 > 数据库 >复杂sql

复杂sql

时间:2023-01-13 23:33:34浏览次数:37  
标签:status lastYearTax 复杂 tax param label item sql


这里记录一条mybatis中的sql,涉及以下几点:

  • 1.foreach
  • 2.大于等于号,小于号
  • 3.foreach遍历
  • 4.模糊匹配
  • 5.and 和or 的复杂拼接
  • 6.一个巧妙的用法:1=0
<select id="findByPageForEntFile" resultMap="resMap2" statementType="STATEMENT">
select <include refid="Base_Column_List2"/> from ent_file e where 1=1

<if test="param.taxFromArea != null">
and tax_from_area = '${param.taxFromArea}'
</if>
<if test='param.labelImpType != null and param.labelImpType!=""' >
<if test="param.labelImpType == 'label_high_legal_risk'">
and ${param.labelImpType} >= 5
</if>
<if test="param.labelImpType != 'label_high_legal_risk'">
and ${param.labelImpType} >= 1
</if>
</if>

<if test='param.zoneId!=null and param.zoneId!="" and param.zoneId!="-1"'>
and zone_id='${param.zoneId}'
</if>
<if test='param.startTime!=null and param.startTime!=""'>
and reg_time >='${param.startTime}'
</if>
<if test='param.endTime!=null and param.endTime!=""'>
and reg_time <='${param.endTime}'
</if>
<if test="param.payTaxStatus != null and param.payTaxStatus != ''">
<if test="param.payTaxStatus == 1">
and last_year_tax >= 0
</if>
<if test="param.payTaxStatus == 2">
and (last_year_tax < 0 OR ISNULL(last_year_tax))
</if>
</if>

<if test='param.startEsDate!=null and param.startEsDate!=""'>
and esdate >= '${param.startEsDate}'
</if>
<if test='param.endEsDate!=null and param.endEsDate!=""'>
and esdate <= '${param.endEsDate}'
</if>

<if test='param.keyWord!=null and param.keyWord!=""'>
and (ent_name like concat('%','${param.keyWord}','%')
or frname like concat('%','${param.keyWord}','%')
or address like concat('%','${param.keyWord}','%')
)
</if>
and delete_flag=0

<if test="param.moveStatusList != null">
and (move_status in
<foreach collection="param.moveStatusList" index="index" item="item" open="(" separator="," close=")">
'${item}'
</foreach>
<if test="param.typeCode2 == 1">
or move_status = NULL
</if>)
</if>
<if test="param.entStatusList != null">
and ent_status in
<foreach collection="param.entStatusList" index="index" item="item" open="(" separator="," close=")" >
'${item}'
</foreach>
</if>
<if test="param.emergentCodeList != null">
and e.eid in
<foreach collection="param.emergentCodeList" index="index" item="item" open="(" separator="," close=")" >
'${item}'
</foreach>
</if>

<if test="param.typeCode == 1">
and
( 1 = 0

<if test="param.labelTaxpayers != null" >
OR label_taxpayers = '${param.labelTaxpayers}'
</if>
<if test="param.labelListed != null" >
OR label_listed = '${param.labelListed}'
</if>
<if test="param.labelHighOperatingRisk != null" >
OR label_high_operating_risk = '${param.labelHighOperatingRisk}'
</if>
<if test="param.labelDishonesty != null" >
OR label_dishonesty = '${param.labelDishonesty}'
</if>


<if test='param.majorProjectStatus!=null and param.majorProjectStatus!=""'>
OR major_project_status= '${param.majorProjectStatus}'
</if>

<if test="param.labelCreditBaseList != null">
OR label_credit_base in
<foreach collection="param.labelCreditBaseList" index="index" item="item" open="(" separator="," close=")" >
${item}
</foreach>
</if>

<if test="param.labelHighnewTechList != null">
OR label_highnew_tech in
<foreach collection="param.labelHighnewTechList" index="index" item="item" open="(" separator="," close=")" >
${item}
</foreach>
</if>

<if test="param.entFinanceRiskList != null">
OR e.eid in
<foreach collection="param.entFinanceRiskList" index="index" item="item" open="(" separator="," close=")" >
'${item}'
</foreach>
</if>

)
</if>

<if test="param.taxEidList != null">
and e.eid in
<foreach collection="param.taxEidList" index="index" item="item" open="(" separator="," close=")">
'${item}'
</foreach>
</if>

HAVING 1 = 1
<if test='param.startLastYearTax!=null and param.startLastYearTax!="" '>
and lastYearTax > '${param.startLastYearTax}'
</if>
<if test='param.endLastYearTax!=null and param.endLastYearTax!="" '>
and lastYearTax <= '${param.endLastYearTax}'
</if>
ORDER BY lastYearTax desc, build_file_status desc,create_time desc
</select>


标签:status,lastYearTax,复杂,tax,param,label,item,sql
From: https://blog.51cto.com/u_15936016/6006794

相关文章

  • DVWA靶场实战(七)——SQL Injection
    DVWA靶场实战(七)七、SQLInjection:1.漏洞原理:SQLInject中文叫做SQL注入,是发生在web端的安全漏洞,主要是实现非法操作,例如欺骗服务器执行非法查询,他的危害在于黑客会有......
  • mysql查看数据库和表使用空间
    –1.切换USEinformation_schema;–2.查看数据库使用大小SELECTconcat(round(sum(data_length/1024/1024),2),'MB')ASDATAFROMTABLE......
  • mysql字符串包含关系查询
    例如判断bill表中,detail字段中不包含money的结果集。SELECT*FROMbillaWHERE!LOCATE(a.money,a.detail);......
  • mysql表字段值处理回车符换行符
    查询数据库时,字段值一直无法匹配上,但是看数据库,觉得没问题,仔细排查后,发现可能是数据入口有问题,导致这个字段的所有的值,后面都加的有回车和换行符。鼠标悬浮时没问题,但是如果......
  • CloudCanal实战-Oracle数据迁移同步到PostgreSQL
    简述本篇文章主要介绍如何使用CloudCanal构建一条Oracle到PostgreSQL的数据同步链路技术要点缩小的数据库权限要求CloudCanal对Oracle数据库的高权限要求,主要......
  • ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061)
    执行命令:mysql-uroot出现如下错误:ERROR2003(HY000):Can'tconnecttoMySQLserveron'localhost'(10061)解决方法:查看my.ini文件,看以......
  • SQL Server 因为数据库正在使用,所以无法获得对数据库的独占访问权。
    今天我在使用SQLServer恢复数据库xxx_db时,出现如下错误:因为数据库正在使用,所以无法获得对数据库的独占访问权。解决方法:1、SQL查询分析器,切换到......
  • MySQL必知必会第八章-用通配符进行过滤
    用通配符进行过滤LIKE操作符通配符(wildcard)用来匹配值的一部分的特殊字符。搜索模式(searchpattern)由字面值、通配符或两者组合构成的搜索条件。搜索子句中使用通配......
  • Android sqlite 使用简介
    进行Android应用开发时经常会用到数据库。Android系统支持sqlite数据库,在app开发过程中很容易通过SQLiteOpenHelper使用数据库,SQLiteOpenHelper依赖于Context对象,但是基于ui......
  • MySQL必知必会第七章-数据过滤
    数据过滤组合WHERE子句操作符(operator)用来联结或改变WHERE子句中的子句的关键字。也称为逻辑操作符(logicaloperator)。AND操作符为了通过不止一个列进行过滤,可使用AND......