mysql - How to design a table for this hierarchical one-to-many model with unbalanced hierarchies?
習慣沉默
習慣沉默 2017-05-18 10:48:38
0
4
669

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

習慣沉默
習慣沉默

reply all(4)
洪涛

The easiest way is to design it like a tree structure

小葫芦

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.

phpcn_u1582

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

迷茫

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)

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!