F
F
fsociety02021-06-24 11:01:30
SQL
fsociety0, 2021-06-24 11:01:30

How to write a SQL query?

There is a peoples table with fields id, name. There is a second table peoples_statistic with fields people_id, gain, date.
Example peoples:
1 Sam
2 Jake
Example peoples_statistic:
1 Sam 25 2019-05-05
1 Sam 30 2019-06-06
1 Sam 10 2019-07-07
2 Jake 20 2019-02-01

To return a table with fields id, name , gain(to sum everything for one person):
1 Sam 65
2 Jake 20

Thanks for the help!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
fsociety0, 2021-06-24
@fsociety0

SELECT *,
       SUM(peoples_statistic.gain) sum_gain,
FROM peoples LEFT JOIN peoples_statistic
ON peoples.id = peoples_statistic.people_id
GROUP BY people.id

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question