一种方法是使用CTE -
with res1 as ( select distinct conf_id, c.mktg_id, mktg_cd from acc_latst c, off_latst ot where c.mktg_id = ot.mktg_id and c.bus_eff_dt > '2019-01-01' and to_date(strt_tms) = '2019-01-10' ) ,res2 as ( select conf_id, count(distinct c.mktg_id) as num_cpg from res1 group by conf_id having count(distinct c.mktg_id) > 1 ) select res1.mktg_id, mktg_cd, count(distinct res1.conf_id) from res1 t1 inner join res2 t2 on t1.conf_id=t2.conf_id group by res1.mktg_id, mktg_cd;
如果查询仍然很慢,您是否可以提供表和分区详细信息。