将SQL查询出来的数据作为一个张“表”,之后根据这张“表”在进行条件查询的实例分析

sql语句演变一:

select ta.a_code, ta.b_code, ta.c_code, ta.a_name, ta.a_time, 
	   tb.b_clazz, tc.c_model, td.d_good	
from tablea ta
left join tableb tb on ta.a_code = tb.a_code  
left join tablec tc on ta.b_code = tc.b_code	 
left join tabled td on ta.c_code = td.c_code	

sql语句演变二:

select tab.a_code, tab.b_code, tab.c_code, tab.a_name, tab.a_time, tab.b_clazz, tab.c_model, tab.d_good
from	
(select ta.a_code, ta.b_code, ta.c_code, ta.a_name, ta.a_time, 
	   tb.b_clazz, tc.c_model, td.d_good	
from tablea ta
left join tableb tb on ta.a_code = tb.a_code  
left join tablec tc on ta.b_code = tc.b_code	 
left join tabled td on ta.c_code = td.c_code) tab

sql语句演变三:

mybatis中的动态sql,条件查询,模糊匹配。

<select id="findmsg" resultmap="某一实体类对应的mapper.xml映射名">  
select tab.a_code, tab.b_code, tab.c_code, tab.a_name, tab.a_time, tab.b_clazz, tab.c_model, tab.d_good  
from      
    (select ta.a_code, ta.b_code, ta.c_code, ta.a_name, ta.a_time,   
           tb.b_clazz, tc.c_model, td.d_good      
    from tablea ta  
    left join tableb tb on ta.a_code = tb.a_code    
    left join tablec tc on ta.b_code = tc.b_code       
    left join tabled td on ta.c_code = td.c_code) tab     
<where>  
    <if test=" a_code != '' and a_code != null ">  
        tab.a_code like concat('%', #{a_code}, '%')  
    </if>  
    <if test=" b_code != '' and b_code != null ">  
        and tab.b_code like concat('%', #{b_code}, '%')  
    </if>  
    <if test=" c_model !='' and c_model != null ">  
        and tab.c_model like concat('%', #{c_model}, '%')  
    </if>  
<where>  
  
</select>  
(0)
上一篇 2022年3月21日
下一篇 2022年3月21日

相关推荐