mcadamsjustin - 1 year ago 64

MySQL Question

I have two tables:

A

`week`

`week`

`Team_Number`

`Points`

A

`Teams`

`Team_Number`

`Session1Points`

I'd like to

`sum`

`Points`

`week`

`week`

`Teams`

`Session1Points`

I've tried:

`UPDATE Teams P`

SET Session1Points =

(SELECT SUM(Points) from week

where week.Team_Number= P.Team_Number)

where P.Team_Number = New.Team_Number

that's not working. I'd like it to trigger after I update the

`week`

`Join`

Answer Source

You can use a JOIN this way

```
UPDATE Teams P
INNER Join (SELECT
Team_Number
, SUM(Points) as team_sum
from week
group by Team_Number ) t on t.Team_Number=P.Team_Number
SET Session1Points = t.team_sum
```