| 优化前: select a.*,b.user_count from (select * from base_material where (material_source='1' or (material_source='2' and companyid={companyid}) or (material_source='3' and departmentid={departmentid})) and type_code not like '09%' {p:sql_condition}) a,base_material_usr_frequency b where a.material_code = b.material_code and b.userid={userid} union all (select base_material.*,0 as user_count from base_material where (material_source='1' or (material_source='2' and companyid={companyid}) or (material_source='3' and departmentid={departmentid})) and material_code not in(select material_code from base_material_usr_frequency where userid={userid}) and type_code not like '09%' {p:sql_condition}) order by user_count desc 优化后:select t_material.*, nvl(t_frequency.user_count, 0) count |