OUTPUT:
SELECT chdt.CHANGEID AS "change_id",
max(stageDef.DISPLAYNAME) AS "Stage",
max(statusDef.STATUSDISPLAYNAME) AS "Status",
longtodate(max(operationtime))
"Operation time" FROM ChangeDetails chdt LEFT JOIN
Change_StageDefinition stageDef ON chdt.WFSTAGEID=stageDef.WFSTAGEID
LEFT JOIN Change_StatusDefinition statusDef ON
chdt.WFSTATUSID=statusDef.WFSTATUSID LEFT JOIN ChangeHistory cdh ON
chdt.CHANGEID = cdh.CHANGEID LEFT JOIN ChangeHistoryDiff cdhd ON
cdh.HISTORYID = cdhd.HISTORYID where (stageDef.DISPLAYNAME = 'Review')
and cdhd.COLUMNNAME in ( 'WFSTAGEID') and
extract(epoch from(now()::TIMESTAMP - to_timestamp(operationtime/1000)::TIMESTAMP))/3600/24 > 2 group by chdt.CHANGEID