简体   繁体   中英

Multiple Many-To-Many relationships scenario in MySQL

I'm a beginner in SQL and Database management, I have an idea that I don't know how to model into database tables.

I have these tables : users , orders , bills , lessons , tickets , coaches .

  • Lessons are posted by coaches.
  • The users are able to order lessons.
  • A bill is registered after the order.
  • The users are also able to order tickets.
  • A ticket gives access to a lesson.
  • When users buy a ticket, the coache benefit or half or the ticket price.

So when a user buy a ticket that costs 6$ for a specific lesson, the coache who owns the lesson will get 3$.

Do I need another bills table for the coaches ? or I can use the same bills table to register their gains from the purchased lessons? I really have no idea how to achive my List of ideas above, sorry.

For now I've just managed to do this, I don't know how to complete the rest of the DB.

|bills|<--|orders| *<------ |users|
            |
            v
            *
        |order_lesson|
            *
            /\
            |
        |lessons| *<----- |coaches|

I can't ask you for a complete answer, but I really need some explication or guidance.

From what I can tell the ticket is no different then a regular order and can be placed with the orders as the only difference is the money the coach gets. So maybe just a column in the orders table would signify the type of order.

 |bills|<--|orders|<----|users|
                / \
                 |
              |lessons|<---|coaches|

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM