Let's say i've got a database with 4 tables:
- users: (personal database)
- id
- user_name
- lessons: (lesson names like math / gym etc.)
- id
- lesson_name
- payments (contains payments with lesson_id and a part of the payment [the whole payment is divided to 12 parts])
- id
- lesson_id
- part
- value
- groups: (to array users to lessons)
- id
- lesson_id
- user_id
My question is how to query the database to get a table with list of all people attending to for ex. math (or any other lesson_id) with their name (probably LEFT JOIN) and SUM of all the payments for each period. The table header for chosen lesson_id should look like:
username | payment 1 | payment 2 | ...(3-11)... | payment 12
I have no clue how to make this work. Maybe my MySQL approach is innapropriate or i should divide it to more queries for more flexibility.
Thank You for your time!