Given the data set for a table person_investments:
| id | person | stock | invested |
|---|---|---|---|
| 1 | Jack | GOOG | 1000 |
| 2 | Jack | META | 800 |
| 3 | Jack | TSLA | 1500 |
| 4 | Jill | GOOG | 4000 |
| 5 | Jill | TSLA | 1000 |
| 6 | Taylor | WMT | 1000 |
| 7 | Taylor | TGT | 2500 |
| 8 | Taylor | HD | 1000 |
I'm trying to figure out how to query and get the stock in which each person is most invested. In this example, I'm looking for this result:
| id | person | stock | invested |
|---|---|---|---|
| 3 | Jack | TSLA | 1500 |
| 4 | Jill | GOOG | 4000 |
| 7 | Taylor | TGT | 2500 |
I've been trying to work with something basic like this:
SELECT id, person, stock, MAX(invested)
FROM person_investments
GROUP BY person;
However, with a real data set, I'm not getting the expected results. What am I getting wrong?