如题,sql文如下,求大大指导如何解读       SELECT 
    t5.* , 
    t_dept.deptname as dept                     
       FROM 
       (SELECT
t1.travel_app_id as Id,                      
t_employeeprofile.employeeno as employeeId,   
   t_employeeprofile.employeename as applyUser, 
t1.app_no as appNo,                           
t1.approve_user_no as approver,               
t1.approve_status as approveStatus,         
t1.crt_timestamp as crtTimeStamp,             
t1.upd_user_id as applyUser,                
t1.upd_timestamp as updTimeStamp,              
t1.employee_id,                                
1 as tbFlg FROM 
t_travel_app t1,       
t_employeeprofile
WHERE 
t1.employee_id=t_employeeprofile.employeeId
<isNotNull prepend="and" property="applyUser">
t_employeeprofile.employeename = #applyUser#
</isNotNull>
<isNotNull prepend="and" property="crtTimeStamp">
t1.crt_timestamp > #crtTimeStamp#
</isNotNull>
<isNotNull prepend="and" property="crtendTimeStamp">
t1.crt_timestamp  &lt;  #crtendTimeStamp#
</isNotNull>
union all SELECT t2.overtime_app_id as Id,
t_employeeprofile.employeeno as employeeId,
    t_employeeprofile.employeename as applyUser,
t2.app_no as appNo,
t2.approve_user_no as approver,
t2.approve_status as approveStatus,
t2.crt_timestamp as crtTimeStamp,
t2.upd_user_id as applyUser,
t2.upd_timestamp as updTimeStamp,
    t2.employee_id,
2 as tbFlg FROM t_overtime_app t2,t_employeeprofile
WHERE
t2.employee_id=t_employeeprofile.employeeId
<isNotNull prepend="and" property="applyUser">
t_employeeprofile.employeename = #applyUser#
</isNotNull>
<isNotNull prepend="and" property="crtTimeStamp">
t2.crt_timestamp > #crtTimeStamp#
</isNotNull>
<isNotNull prepend="and" property="crtendTimeStamp">
t2.crt_timestamp   &lt;  #crtendTimeStamp#
</isNotNull>
union all SELECT
t3.abnormal_work_app_id as Id,
t_employeeprofile.employeeno as employeeId,
    t_employeeprofile.employeename as applyUser,
t3.app_no as appNo,
t3.approve_user_no as approver,
t3.approve_status as approveStatus,
t3.crt_timestamp as crtTimeStamp,
t3.upd_user_id as applyUser,
t3.upd_timestamp as updTimeStamp,
    t3.employee_id,
3 as tbFlg FROM t_abnormal_work_app t3,t_employeeprofile
WHERE 
t3.employee_id=t_employeeprofile.employeeId
<isNotNull prepend="and" property="applyUser">
t_employeeprofile.employeename = #applyUser#
</isNotNull>
<isNotNull prepend="and" property="crtTimeStamp">
t3.crt_timestamp > #crtTimeStamp#
</isNotNull>
<isNotNull prepend="and" property="crtendTimeStamp">
     t3.crt_timestamp  &lt;  #crtendTimeStamp# 
</isNotNull>
union all SELECT
t4.leave_app_id as Id,
t_employeeprofile.employeeno as employeeId,
t_employeeprofile.employeename as applyUser,
t4.app_no as appNo,
t4.approve_user_no as approver,
t4.approve_status as approveStatus,
t4.crt_timestamp as crtTimeStamp,
t4.upd_user_id as applyUser,
t4.upd_timestamp as updTimeStamp,
    t4.employee_id,
4 as tbFlg FROM 
t_leave_app t4,
t_employeeprofile
    WHERE 
t4.employee_id=t_employeeprofile.employeeId
<isNotNull prepend="and" property="applyUser">
t_employeeprofile.employeename = #applyUser#
</isNotNull>
<isNotNull prepend="and" property="crtTimeStamp">
t4.crt_timestamp > #crtTimeStamp#
</isNotNull>
<isNotNull prepend="and" property="crtendTimeStamp">
t4.crt_timestamp   &lt; #crtendTimeStamp#
</isNotNull>
) as t5,   t_employee,t_establishment,t_dept
     where
t5.employee_id=t_employee.employeeid
and
     t_employee.establishmentid=t_establishment.establishmentid
     and t_establishment.deptid=t_dept.deptid
<isNotNull prepend="and" property="employeeid">
t5.employeeId = #employeeid#
</isNotNull>
<isNotNull prepend="and" property="deptid">
t_dept.deptid= #deptid#
</isNotNull>
order by crtTimeStamp asc

解决方案 »

  1.   

    <isNotNull prepend="and" property="applyUser">
    t_employeeprofile.employeename = #applyUser#
    </isNotNull>就是如果applyUser != null
    就加上
    and t_employeeprofile.employeename = #applyUser#
      

  2.   

    你看不明白的只是iBatis框架的SQL标签罢了,<isNotNull> 是表示如果传入参数是空则不会加入sql中语句。
    网上关于iBatis的资料很多,LZ查查学下吧