I'm writing a query to return some data back from multiple tables. I've anonymized the data, but you should still be able to understand the problem

```
select distinct device.gamertag, count(network.trophies) as `Trophies`, person from people
inner join device on people.gamertag=device.gamertag
inner join network on device.consoledevicename=network.consoledevicename
group by device.gamertag order by count(network.trophies) desc

```

I'm left with a results that looks something like this

| Gamertag | Trophies | Person |
| --- | --- | --- |
| TheGreatJuan | 45 | Juan |
| Juan46 | 155 | Juan |
| NewGT5555 | 3 | Lucas |
| TheGreatJuan2 | 77 | Juan |
| GuestAccount | 1 | Guest |

My tables looks like this:

* Person

| Gamertag | Person |
| --- | --- |
| TheGreatJuan | Juan |
| Juan46 | Juan |
| NewGT5555 | Lucas |
| TheGreatJuan2 | Juan |
| GuestAccount | Guest |

* Device

| gamertag | consoledevicename |
| --- | --- |
| TheGreatJuan | JuansPS4 |
| Juan46 | JuanPS5 |
| NewGT5555 | LucasXbox |
| TheGreatJuan2 | JuanPS4 |
| GuestAccount | LucasXbox360 |

* Network

| trophies | consoledevicename |
| --- | --- |
| MGS2 | JuansPS4 |
| MGS2 | JuanPS4 |
| MGS3 | JuanPS4 |
| SAMPL5 | LucasXbox |
| RED6 | JuanPS5 |
| BLU8 | LucasXbox360 |

I want to be able to take my existing query and aggregate how many trophies a person has on all their accounts. For the sake of this questions, please assume that a person can have 2 or more trophies of the same kind, which is why they need filtered out.

My desired results looks like:

| Name | Trophies |
| --- | --- |
| Juan | 277 |
| Lucas | 3 |
| Guest | 1 |

Thanks in the advance!