首页 > sql查询时如何动态更换连接表

sql查询时如何动态更换连接表

当type == 1时,course_id关联的时t_course_info 这张表

当type == 2时,course_id关联的是t_venue_course_info这张表

所以现在,我在查询的时候,如何才能根据type来判断关联哪张表呢?而且查询的时候会对关联表的数据进行筛选。

求大家帮忙!


mysql有case when 具体自己摸索下


Mybatis的isEqual是可以实现这个动态sql,但是这是两个业务直接写两个sql不就好了吗


select * from course c
left join t_course_info tci
on tci.id = c.course_id and c.type = 1
left join t_venue_course_info tvci
on tcvi.id = c.course_id and c.type = 2
【热门文章】
【热门文章】