Skip to content
Advertisement

How to sum the minutes of each activity in Postgresql?

The column “activitie_time_enter” has the times.

The column “activitie_still” indicates the type of activity.

The column “activitie_walking” indicates the other type of activity.

Table example:

What I need is to sum up the total minutes for each activity separately. Any suggestions or solution?

Advertisement

Answer

First calculate the duration for each activity (the with CTE) and then do conditional sum.

BTW do you really need two columns (activitie_still and activitie_walking)? Only one activity column with those values will do. This will allow more activities (Running, Sleeping, Working etc.) w/o having to change the table structure.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement