Home > database > SQL in a table, the relations between entities, and the associated lead to low efficiency problem?
SQL in a table, the relations between entities, and the associated lead to low efficiency problem?
Time:09-24
Situation: such as now there is A A city all school students information table student (1000 w), whether classmates before now needs between students and students (condition is confronting) same level, so the question becomes, since this student and student association, will produce A lot of correlation [50 people, such as A class x and 49 other personal relationship] is generated and lead to low efficiency, could you tell me is there A better way to solve? ! Consult!
CodePudding user response:
Need to use a table, change the idea, first find out two students all schools, which, class, and then according to these three groups, if there is greater than 2 records are classmates, otherwise not.
select * from ( Select count (1) the nm, stu. School id, stu. Id, the level to which the stu. Class The from student stu Where stu. Id=Anderson d or stu. Id=B.i d Group by stu. School id, stu. Id, the level to which the stu.) class b where b.n m> 1