我正在将视图从MySQL 5.0迁移到Oracle 12c。这是MySQL中的代码和输出的一部分:
select tb1.courtUuid AS courtUuid,
tb1.uuid AS caseRecordUuid,
tb1.statusCode AS statusCode,
tb1.caseTrackingId AS caseTrackingId,
tb1.instantiationDateTime AS created,
crs.description AS caseRecordStatusDescription,
lct.description AS caseTypeDescription,
lcc.description AS caseTypeDescription2,
max(crh.eventDateTime) AS lastEventDateTime,
eventType.code as event_code,
eventType.description AS lastEventDescription,
tb8.firstName AS defendantFirstName,
tb8.lastName AS defendantLastName,
concat(lawyer.firstName,' ',lawyer.lastName) AS lawyerName,
lawyer.uuid AS lawyerUuid
from tb1
join tb2 crs
join tb3 lct
join tb4 lcc
join tb5 crh
join tb6 eventType
join tb7 pp
join tb7 lawyerPP
join tb8
join tb8 lawyer
where ((tb1.caseTypeCode = 1)
and (tb1.clearFilingFlag = 0)
and (tb1.deletedFilingFlag = 0)
and (tb1.archivedFlag = 0)
and (tb1.statusCode = crs.code)
and (tb1.localCaseTypeCode = lct.code)
and (tb1.localCaseCategoryCode = lcc.code)
and (crh.eventTypeCode = eventType.code)
and (tb1.uuid = pp.caseRecordUuid)
and (pp.relationshipCode = 2)
and (pp.personUuid = tb8.uuid)
and (tb1.uuid = crh.caseRecordUuid)
and (lawyerPP.personUuid = lawyer.uuid)
and (lawyerPP.relationshipCode = 4)
and (lawyerPP.caseRecordUuid = tb1.uuid))
group by crh.caseRecordUuid
order by crh.caseRecordUuid
这是Oracle 12c中的代码,也是其输出的一部分:
select max(tb1.courtUuid) AS courtUuid,
max(tb1.uuid) AS caseRecordUuid,
max(tb1.statusCode) AS statusCode,
max(tb1.caseTrackingId) AS caseTrackingId,
max(tb1.instantiationDateTime) AS created,
max(crs.description) AS caseRecordStatusDescription,
max(lct.description) AS caseTypeDescription,
max(lcc.description) AS caseTypeDescription2,
max(crh.eventDateTime) AS lastEventDateTime,
max(eventType.code) AS code,
min(eventType.description) AS lastEventDescription,
max(tb8.firstName) AS defendantFirstName,
max(tb8.lastName) AS defendantLastName,
max(lawyer.firstName || ', ' || lawyer.lastName) AS lawyerName,
max(lawyer.uuid) AS lawyerUuid
from tb1
join tb2 crs
on (tb1.statusCode = crs.code)
join tb3 lct
on (tb1.localCaseTypeCode = lct.code)
join tb4 lcc
on (tb1.localCaseCategoryCode = lcc.code)
join tb5 crh
on (tb1.uuid = crh.caseRecordUuid)
join tb6 eventType
on (crh.eventTypeCode = eventType.code)
join tb7 pp
on (tb1.uuid = pp.caseRecordUuid)
join tb7 lawyerPP
on (lawyerPP.caseRecordUuid = tb1.uuid)
join tb8
on (pp.personUuid = person.uuid)
join tb8 lawyer
on (lawyerPP.personUuid = lawyer.uuid)
where ((tb1.caseTypeCode = 1)
and (tb1.clearFilingFlag = 0)
and (tb1.deletedFilingFlag = 0)
and (tb1.archivedFlag = 0)
and (pp.relationshipCode = 2)
and (lawyerPP.relationshipCode = 4))
group by crh.caseRecordUuid
order by crh.caseRecordUuid
Oracle 12c中代码的输出应该与MySQL相同。所有其他列的输出是相同的,但是对于列代码(在MySQL中)和CODE(在Oracle中),输出是不同的,以及列description_3(在MySQL中)应该与LASTEVENTDESCRIPTION相同(在甲骨文)。标记的行不匹配。
我需要Oracle中的GROUP BY子句只有crh.caseRecordUuid,否则,我不会获得与MySQL相同的行数。向GROUP BY子句添加更多列会向输出添加更多行。输出应该与MySQL中的输出相同。
如果可以的话,请帮我解决这个问题。