I have a table for timeTracks with the properties startTime and stopTime that are recorded for another table called project.
With the following aggregates I managed to display the count and sum of the amount of tracks that belongs to a project. In case an active Track (one without stopTime) exists, I want 2 additional columns named "activeTrackId" and "activeTrackStartTime".
SLECT
count(time_track."timeTrackId") AS "timeTracksTotalCount",
floor(date_part('epoch'::text, sum(time_track."stopTime" - time_track."startTime")))::integer AS "timeTracksTotalDurationInSeconds"
activeTimeTrackId ??
activeTimeTrackStartTime ??
...
FROM project
LEFT JOIN time_track on time_track."fkProjectId" = project."projectId"
Technically there can be only one active track at a time. However just in case, it should only select the latest active track, if there a two tracks without stopTime.
How can I that in postgres?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…