我自己写的原sql select a.xzq,a.bm,a.sj,count(distinct b.SFZ) from(select distinct b.xzq,b.bm,to_date(to_char(a.sj,'yyyy-mm'),'yyyy-mm')as sj from a,b where a.sfz = b.sfz and a.sj>= to_date('2020-01-01 00:00:00','yyyy-mm-dd hh24:mi:ss') and a.sj < to_date('2020-12-01 00:00:00','yyyy-mm-dd hh24:mi:ss') )a left join (select b.xzq,b.bm,to_date(to_char(a.sj,'yyyy-mm'),'yyyy-mm')as sj,a.sfz from a,b where a.sfz = b.sfz and a.sj>= to_date('2020-01-01 00:00:00','yyyy-mm-dd hh24:mi:ss') and a.sj < to_date('2020-12-01 00:00:00','yyyy-mm-dd hh24:mi:ss') )b on (a.xzq=b.xzq and a.bm = b.bm and a.sj>=b.sj) group by a.xzq,a.bm,a.sj 运行起来很慢,想请教一下各位大佬,可以改的更简洁一些,更快一些吗,数据库是Oracle |