简体   繁体   English

多对多选择:缺少数据

[英]many-to-many select: missing data

In a university db I have a many-to-many relationship between students and modules that they are registered to: using a bridging table of status . 在大学数据库中, 学生和他们注册的模块之间存在多对多的关系:使用状态桥接表。

The bridging table status has a multi-field primary key (using the unique combination of student and module ; stud_id and mod_id) 桥接表状态具有多字段主键(使用StudentModule的唯一组合; stud_id和mod_id)

However, when returning data from a general select query designed to list all this data: 但是,从旨在列出所有这些数据的常规选择查询返回数据时:

SELECT status.stud_id, student.fname, student.sname, status.mod_id, modle.mtitle, status.grades
FROM status
INNER JOIN modle
ON status.mod_id=modle.mod_id 
INNER JOIN student
ON status.stud_id=student.stud_id 
GROUP BY status.stud_id

the query will not take into account that the students may have many modules, and will only display students as having a single module. 该查询将没有考虑到的是,学生可以具有许多模块,并且将仅显示学生为具有单个模块。

Why do you use GROUP BY status.stud_id ? 为什么使用GROUP BY status.stud_id That's the reason why you have only one result for student. 这就是为什么只有一个学生成绩的原因。

I don't see any aggregate function within your query, so you probably can just delete GROUP BY : 我在查询中没有看到任何聚合函数,因此您可能只需删除GROUP BY

SELECT status.stud_id, student.fname, student.sname, status.mod_id, modle.mtitle, status.grades
FROM status
INNER JOIN modle
ON status.mod_id=modle.mod_id 
INNER JOIN student
ON status.stud_id=student.stud_id 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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