复杂sql语句 组合判断other choose where and if

// 处理模糊查询 百分号问题
 <select id="getRolePage" resultType="com.tiansu.hlms.toc.bean.role.vo.RoleVoList">
    select id as id,role_name as roleName,role_code as roleCode,description,tenant_id as tenantId from hlms_toc_role where disabled=0
    <if test="keyword!=null and keyword!=''">
      and (role_name like CONCAT('%',concat('/',#{keyword},'%')) ESCAPE '/' or
      role_code like CONCAT('%',concat('/',#{keyword},'%')) ESCAPE '/')
    </if>
  </select>
-------
 <select id="selectByDocPatFollow" resultMap="BaseResultMap">
    select a.id,cn_name,a.latest_time,a.follow_count,a.icon,a.flowup_cycle,a.sex,a.is_overTime,a.mobile
    from jf_sys_patient a
    left join jf_doctor_pat b on a.id=b.pat_id where b.doctor_id=#{docId} and a.follow_count !=0
    <if test="name != null and name != ''">
      and cn_name like  concat(#{name},'%')
    </if>
    <choose>
      <when test='num=="2"'>order by follow_count desc</when>
      <when test='num=="1"'>order by follow_count asc</when>
    </choose>
    <choose>
      <when test="date=='1'.toString()">order by latest_time desc</when>
      <when test="date=='2'.toString()">order by latest_time asc</when>
    </choose>
  </select>
去掉第一个where
 select id, tenant_id, title, subtitle, `type`, type_details, reporter, report_time, template_id, document_id,
        document_type, reporter_name, document_path, DATE_FORMAT(report_time, '%Y-%m-%d') AS document_date
        from hlms_report_document
        <where>
        <if test="tenantIdList!=null and tenantIdList.size()&gt; 0">
            and tenant_id in
            <foreach item="item" index="index" collection="tenantIdList" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="keyword != null and keyword != ''">
            and subtitle LIKE CONCAT('%',replace_special_str_fun(#{keyword}),'%') ESCAPE '/'
        </if>
        <if test="startDate != null and startDate != '' ">
            and date_format(report_time,'%Y-%m-%d') &gt;= #{startDate}
        </if>
        <if test="endDate != null and endDate != ''">
            and date_format(report_time,'%Y-%m-%d') &lt;= #{endDate}
        </if>
        </where>
        order by report_time desc
<select id="getPatientListTwo" resultType="com.jianfan.mdt.patient.vo.PatListVo">
    select distinct a.id as id,a.cn_name as cnName,a.mobile as
    mobile,a.source as source,a.sex as sex,a.date_birth as dateBirth,
    a.icon as icon,a.im_id as imId,a.create_time as createTime, a.dis_host as disHost,
    a.mdt_status as mdtStatus,a.mdt_count as mdtCount,host_office as hostOffice,host_id as hostId,'${readWrite}' as operAuth
    from jf_sys_patient a
    <choose>
      <when test="typeId=='2'.toString()">
       <choose>
         <when test='source=="1"'>
           left join jf_doctor_pat b on a.id=b.pat_id where b.doctor_id=#{docId} and a.create_user=#{docId}
           <if test="hostId!=null and hostId!=''">
             and a.host_id=#{hostId}
           </if>
           <include refid="patListTwo"/>
           and a.is_use=1
         </when>
         <otherwise>
           where  a.host_id=#{hostId}
            <choose>
              <when test='source=="4"'>
                and source='1'
              </when>
              <otherwise>
                <if test="source!=null and source!='' and source!='0'.toString()">
                  and  a.source=#{source}
                </if>
            </otherwise>
            </choose>
           <include refid="patListTwo"/>
           and a.is_use=1
         </otherwise>
       </choose>
      </when>
      <when test="typeId=='3'.toString()">
        left join jf_doctor_pat b on a.id=b.pat_id where b.doctor_id=#{docId}
        <if test="source=='1'.toString()">
          and a.create_user=#{docId}
        </if>
        <include refid="patListTwo"/>
        and a.is_use=1
      </when>
      <when test="typeId=='4'.toString()">
        <choose>
          <when test="source=='1'.toString()">
            left join jf_doctor_pat b on a.id=b.pat_id where b.doctor_id=#{docId} and a.create_user=#{docId}
            <include refid="patListTwo"/>
            and a.is_use=1
          </when>
          <otherwise>
            where a.host_office=#{hostOffice}
            <if test="source!=null and source!='' and source!='0'.toString()">
              and  a.source=#{source}
            </if>
            <include refid="patListTwo"/>
            and a.is_use=1
          </otherwise>
        </choose>
      </when>
      <otherwise>
       <choose>
         <when test="source=='1'.toString()">
           left join jf_doctor_pat b on a.id=b.pat_id where b.doctor_id=#{docId} and a.create_user=#{docId}
           <if test="hostId!=null and hostId!=''">
             and a.host_id=#{hostId}
           </if>
           <include refid="patListTwo"/>
           and is_use=1
         </when>
         <otherwise>
           <trim prefix="where"  prefixOverrides="and">
             <if test="hostId!=null and hostId!=''">
               and a.host_id=#{hostId}
             </if>
             <choose>
               <when test="source=='4'.toString()">
                 and source='1'
               </when>
               <otherwise>
                 <if test="source!=null and source!='' and source!='0'.toString()">
                   and  a.source=#{source}
                 </if>
               </otherwise>
             </choose>
            <include refid="patListTwo"/>
             and is_use=1
           </trim>
         </otherwise>
       </choose>
      </otherwise>
    </choose>
    order by create_time desc

  </select>

msql 在delete from 表名 如果给表起了表明 需要在 delete 后面加上别名的名称 如 delete a from test as a

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
SoftTree SQL Assistant v5.0 - What's New New Code Analysis and Refactoring Functions - smart object, column, and parameter renaming methods; smart code extraction methods; advanced code dependencies analysis Graphical analysis of dependencies for objects (tables, views, procedures, functions), table and view columns, procedure and function parameters. Code refactoring - Extract View definition from procedural code - 3 clicks method for conversion of a block of code to a view - customizable templates. Code refactoring - Extract sub procedure definition from procedural code - 3 clicks method for conversion of a block of code to a stored procedure or function - customizable templates. Code refactoring - Rename procedure/function in database including automatic discovery of dependencies, code preview before updating, including all dependencies. Code refactoring - Rename table/view in database including automatic discovery of dependencies, code preview before updating, including all dependencies. Code refactoring - Rename table/view column view in database including automatic discovery of dependencies, code preview before updating, including all dependencies. Code refactoring - Rename procedure/function parameter in database including automatic discovery of dependencies, code preview before updating, including all dependencies. Code refactoring - rename local variable - rename local variables in procedures and functions (standalone code loaded in the editor or part of a large script). Syntax checker improvements - highlighting for unused variables. Advanced Code Entry Automation - updated code snippets engine, programmable code snippets using SQL language Support for user-defined interactive prompts. See new $PROMPT$ macro . User-defined programmable macros using SQL code. See new $$..$$ and accompanying macros $CURRENT_NAME$, $CURRENT_SEL$, etc... . Removed certain limitations on the use of functionally similar macros in the same snippet code. For example, $COLUMNS$ and $COLUMNS_KEYS$ macros can be now used in the same code snippet. Improved SQL Intellisense and Code Formatting Improved keyword prompts - preferred keywords and SQL constructs displayed on top of the keyword prompts. You can now customize preferred keywords list to match your preferences. Column popups after ORDER BY and GROUP BY keywords are now feature checkboxes. Multiple columns can be picked at once. While-you-type and standalone code formatters support new formatting options allowing simultaneous use of different cases for keywords and for system functions, for example uppercasing keywords and using mixed or lower case for system functions. New options for handling name delimiters. "Always Add Delimiters" option supports new mode "Only if name = keyword (limited)" You can now customize list of keywords that you also use as object and column names, and which you don't want SQL Assistant to treat as keywords, for example, the default configuration includes ID and Name, names, you can add your own. "Show Keys and Indexed Columns" is preset for all assistance types by default. Primary keys, foreign keys, and indexed columns are displayed by default in column popups and mouse-over hints. Mouse-over hints for table and view columns display hyperlinks for sample data preview and for DDL code view for views. . Mouse-over hints for procedure and function parameters display hyperlinks for procedure/function DDL code view. Improved display of column name popups for PostgreSQL. The popups now indicate auto-generated values and indexed columns. Improved recognition of auto-generated values in various SQL statements. For example, SQL Assistant does not insert references to "timestamp" columns in SQL server when generating code for table INSERT and UPDATE statements. Improved control of column name popups. You can now configure additional symbols that trigger automatic column name popups, for example, you may add <, <>, >, BETWEEN and other symbols to trigger automatic column popup display. SQL Intellisense implemented for CREATE INDEX statement. SQL Intellisense implemented for CREATE OR REPLACE AND COMPILE JAVA SOURCE. Preset code formatting rule added for Oracle VARRAY. Preset code formatting rule added for DEFAULT VALUES in INSERT/UPDATE statements in Transact-SQL. Database name and schema name completion is now supported after Ctrl+Space. That is handy if you work with long names and need to type them often. Behavior change for query suggestions based on code entry history. To avoid accidental insertion of historical queries into the code, historical items are not pre-selected automatically. . Added new option for controlling alias generation. You can now specify name prefixes that you want SQL Assistant to ignore. Database Code Unit Testing Framework New complete database code unit testing framework supports interactive and automated database code unit testing; allows quick bulk setup of unit tests for multiple database projects. New Add-ons Add-ons for Delphi with built-in SQL Editor. Add-ons are available for all Delphi Windows versions from Delphi 2005 to Delphi 2010;. Experimental support for pre-release version of Visual Studio 2010 ( limited testing performed on Windows XP and Vista). Data Import/Export/Generation New test data generator for quickly populating tables and schemas with realistic test data. Supports updates of multiple tables in one project. Enhanced scripting and exporting table data now this feature supports exporting data from multiple tables and views, as well as from multiple schemas. Miscellaneous Syntax Check Results and Messages panes support copying and saving messages. New user-friendly interface for protecting from run-away queries and results. Added handling for XML windows in SQL Server Management Studio. SQL Intellisense is disabled in XML windows. Improved SEH (Structure Exception Handler) for better code quality and support. Added new API functions, including new function for off-line code formatting, with support for multiple files. A number of other minor improvements

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值