这几天在一个数据库元数据的整理出现了两个sql,做的时候,有点迷糊,后来转过来琢磨了一下,两条sql如如下:
select a.*, b.bm, b.lm
from xt_sjzlgzpz_t a
left join xt_sjzlgzpz b
on upper(trim(a.lm)) = upper(trim(b.lm))
where upper(b.bm) = upper(‘TB_STAT_YWL_Report‘)
和
select a.*, c.bm, c.lm
from xt_sjzlgzpz_t a
left join (select *
from xt_sjzlgzpz b
where upper(b.bm) = upper(‘TB_STAT_YWL_Report‘)) c
on upper(trim(a.lm)) = upper(trim(c.lm))
这两条sql主要区别是先join还先where,论效率肯定是后者高,并且可以真正显示left join效果,而前者就不可以!!!
时间: 2024-10-13 12:33:55