Greetings. I have 3 tables below. One shows 'posts' The second shows 'file_logs' It stores records of each time a file is downloaded. The third shows 'relationships' between posts and files. Usually two files are connected to 1 post.
I would like to show sums of 'file ids' grouped by their related post id.
For example, 2 files are connected to one post. I need the sum of how many times those 2 files are downloaded . What would be the best way to do this? Thank you.
1) Table "Posts":
p.id | p.title
1 |||| Title1
2 |||| Title2
3 |||| Title3
2) Table file_logs (records every time a file is downloaded):
f.id || f.file_id (id of which file is downloaded)
1 ||||||| 2
2 ||||||| 3
3 ||||||| 4
4 ||||||| 3
5 ||||||| 3
6 ||||||| 2
7 ||||||| 4
3) Table "relationships" ( stores relationship between posts and download files; often 2 files are connected to one post):
r.id (post p.id) | r.file_id (f.file_id)
1 ||||||||||||||||| 2
1 ||||||||||||||||| 3
2 ||||||||||||||||| 4
2 ||||||||||||||||| 5
3 ||||||||||||||||| 6
3 ||||||||||||||||| 7
I would like to show sums of 'file ids' grouped by their related post id.
For example, 2 files are connected to one post. I need the sum of how many times those 2 files are downloaded . What would be the best way to do this? Thank you.
1) Table "Posts":
p.id | p.title
1 |||| Title1
2 |||| Title2
3 |||| Title3
2) Table file_logs (records every time a file is downloaded):
f.id || f.file_id (id of which file is downloaded)
1 ||||||| 2
2 ||||||| 3
3 ||||||| 4
4 ||||||| 3
5 ||||||| 3
6 ||||||| 2
7 ||||||| 4
3) Table "relationships" ( stores relationship between posts and download files; often 2 files are connected to one post):
r.id (post p.id) | r.file_id (f.file_id)
1 ||||||||||||||||| 2
1 ||||||||||||||||| 3
2 ||||||||||||||||| 4
2 ||||||||||||||||| 5
3 ||||||||||||||||| 6
3 ||||||||||||||||| 7