Sorry if my question’s title is confusing. It’ll be easier to look at my code/example below.
I am trying to sum each activity stored in my DB by each of their elapsed time (field value) and then group them by week. I feel like I’m close. Currently, this is my query:
SELECT week, activityType, SUM (elapsedTime) AS activityTotalTime FROM activity WHERE year=2017 AND activityType IN ('rockclimbing', 'hike', 'run') GROUP BY week, activityType;
This produces a result like:
But what I would really like is:
How can I achieve this with SQL? Is this a case for a pivot? How to do that?