There are better ways to do this in Oracle.
SELECT recordID,
COUNT(c1.recordID) as totalRecords,
MAX(c1.expAverage) AS high,
MIN(c1.expAverage) AS low,
MAX(c1.expAverage) KEEP (DENSE RANK FIRST ORDER BY recordId) as open,
MAX(c1.expAverage) KEEP (DENSE RANK LAST ORDER BY recordId) as close,
SUM(totalVolume) as totalVolume,
trunc(calculationDate, 'YYYY-MM-DD HH') as calculationDate
FROM calculation c1
GROUP BY trunc(calculationDate, 'YYYY-MM-DD HH')
ORDER BY calculationDate ASC;
Note these changes:
- The use of
trunc(CalculationDate . . .)
rather then extracting each component. - The removal of
CalculationDate
from theSELECT
clause. This is an error in Oracle. Note: I think the "clean" hour is a better choice than an arbitrary value. But, you can put inMIN(calculationDate)
to better emulate the MySQL code if you really want. - The use of
keep
syntax rather than a subquery.