Home  >  Q&A  >  body text

mysql - How to design a table for this hierarchical one-to-many model with unbalanced hierarchies?

Recently encountered a very tangled business model:
We need to design a question bank for a teacher training institution. Each question in the question bank belongs to a certain branch. The key weird thing is the definition of this branch. This branch is in the business The above is defined as follows:
First of all, it is divided into schooling stages: kindergarten, elementary school, junior high school, and high school.
Under the schooling stage, there are first-level subjects,
Children: comprehensive quality, childcare skills
Primary school: comprehensive Quality, educational ability, professional and technical ability
Junior high school: comprehensive quality, teaching ability, professional and technical ability
High school: comprehensive quality, teaching ability, professional and technical ability

Then, under "professional and technical ability", it is also divided into Chinese, mathematics, and English. . . . Wait for the second-level subjects, and the lower-level subjects in elementary school, junior high school, and high school are different. However, there are no second-level subjects such as comprehensive quality and educational ability.

So this imbalance in grading leads to a very embarrassing phenomenon in the questions in this question bank
Some questions belong to the first-level subjects, while some questions belong to the second-level subjects

Of course I can build the question bank table like this

Question id Question name 1st level discipline 2nd level discipline

But I always feel that something is wrong, but I can’t tell what is wrong.
Please give me some advice

習慣沉默習慣沉默2710 days ago667

reply all(4)I'll reply

  • PHP中文网

    PHP中文网2017-05-18 10:50:38

    The easiest way is to design it like a tree structure

    reply
    0
  • 高洛峰

    高洛峰2017-05-18 10:50:38

    It might be like this

    Discipline (id, subject name, subject level, parent subject);

    This is for reference only. The details can be further divided according to the operation. It does not necessarily have to be a table.

    reply
    0
  • phpcn_u1582

    phpcn_u15822017-05-18 10:50:38

    Subject table (subject id, subject name, subject level, superior subject level, stage id)
    Question table (topic id, subject id, question content)

    reply
    0
  • 迷茫

    迷茫2017-05-18 10:50:38

    Create three new tables to solve the problem, academic period table, subject table, test question table
    Academic period table (id, name)
    Subject table (id, name, level, parent subject id)
    Examination table (id, name, test question Content, academic stage id, subject id)

    reply
    0
  • Cancelreply