将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 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 Tab.a_code LIKE CONCAT('%', #{a_code}, '%') AND Tab.b_code LIKE CONCAT('%', #{b_code}, '%') AND Tab.c_model LIKE CONCAT('%', #{c_model}, '%')