我的查询的精简版本在下面(因为有多少变量),当我运行子查询本身时它运行在2秒内,但是当我围绕它时,它需要超过半小时。我检查了所有列名 - 两次。这是为什么发生?我能做些什么来解决它?需要很长时间的Oracle查询
SELECT Amount, Comments, FirstName, LastName, TermName, AdjustmentType, Void_Indicator FROM ( Select c.amount amount, c.comments comments, p.firstname firstname, p.lastname lastname, e.termname termname, c.adjustmenttype adjustmenttype, b.voidindicator void_indicator From ChargesDTL c, ChargesHDR b, PeopleHDL p, TermMaster e Where ( b.studentnumber=p.studentnumber and c.termid = e.term_id and b.adjustmentnumber=c.adjustmentnumber and p.personID=b.personID and b.locationcode='12' ) Union Select c.amount amount, c.comments comments, p1.firstname firstname, p1.lastname lastname, e.termname termname, c.adjustmenttype adjustmenttype, b.voidindicator void_indicator From ChargesDTL c, ChargesHDR b, PeopleHDL p1, TermMaster e Where ( b.studentnumber=p.studentnumber and c.termid = e.term_id and b.adjustmentnumber=c.adjustmentnumber and p1.personId = b.personId and b.locationcode='13' ) order by adjustmenttype )
这可能是一个查询。派生表不是必需的 –