2 u013425577 u013425577 于 2016.03.31 14:31 提问

Mysql like语句值不固定

    SELECT e.`ID`,e.`EmployeeID`,e.`CHNName`,e.`ENGName`,e.`Sex`,e.`Mobile` 
        FROM tb_pcm_coach c,tb_sys_employee e,tb_sys_employeetype tt, tb_sys_department d  
        WHERE c.ID=e.ID AND e.ID=tt.Employee AND e.dept = d.id
        <!--  AND tt.EmployeeType='EB43871E-1E7C-48CB-B38D-9E3200D011F7}'-->
        AND e.STATUS='FDCAAF7C-8FE8-4340-993E-9E29000B6F14' 
        <!--AND c.ID IN(SELECT coach FROM tb_mms_coachbuy) -->

        <if test="employeetype != null and '' != employeetype">  
            and tt.EmployeeType= #{employeetype}
        </if>
        <if test="dept != null and '' != dept">  
            and INSTR(d.TreeKey, #{dept}) = 1
        </if>
        <if test="coachlevel != null and '' != coachlevel">  
            and c.CoachLevel= #{coachlevel}
        </if>
        <if test="eid != null and '' != eid">  
            and e.ID != #{eid} 
        </if>
        <!-- Combobox精确查询 -->
        <if test="CHNName != null and '' != CHNName">  
            and e.CHNName like '%#{CHNName}%' 
        </if>
</select>
最下面like我想查e.CHNName包括传入的CHNName,也就是like的值不固定,请问应该怎么写?

已解决,我从其他模块借鉴的
<if test="departmentname != null and '' != departmentname">
        and INSTR(d.departmentname,#{departmentname}) > 0
</if>
mysql中有一个方法 INSTR可以比对两个字符串。

2个回答

CSDNXIAON
CSDNXIAON   2016.03.31 14:45

mysql like语句
----------------------同志你好,我是CSDN问答机器人小N,奉组织之命为你提供参考答案,编程尚未成功,同志仍需努力!

u010030637
u010030637   2016.03.31 15:12

‘%${CHNName}%’
不知道是不是你想要的答案 .

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!