-2

I have a table as follows:

name        week    effort
quentin     1       1
quentin     1       2
quentin     2       1
tracy       1       1       
joe         2       2

There will only be a handful of unique names so it doesn't need to be dynamic

And I would like to query it to return something like

week    QuentinEffortSum    TracyEffortSum  JoeEffortSum
1       3                   1               0
2       1                   0               2

I have tried something along the lines of

SELECT SUM(Effort) AS JoeEffort, Min (Week) AS week FROM [Group$]
WHERE name = "Joe"
GROUP BY week
ORDER By week

which returned:

week   JoeEffort
1      3
2      1

and now I need the other columns and imagine in involves joins but am not sure how to complete the task

Please help

Thanks

1 Answers1

1

I think a PIVOT table would work, like so:

SELECT *
FROM (
    SELECT 
        week,name,effort 
    FROM [Group$]
) as s
PIVOT
(
    SUM(effort)
    FOR [name] IN ('quentin','joe','tracy')
)AS pvt
sgtrice1
  • 101
  • 4