mysql - Student's report
问题描述
I need a student's mark report.
I have the following tables:
- user table with: user_id, first name, last name, course_id
- a course table with: course_id, name
- a subject table with: subject_id, course_id, name
- a marks table with: mark, subject_id, course_id, user_id
I need to show all students from a selected course with all their marks for all their subjects.
For example: course_id = 18
Last Name | Name | Math | Geography | Science | Physics
Doe | John | 8 | 7 | 4 | 7
Doe | Jane | 5 | 8 | 4 | 6
and so on until the last student ordered alphabetically using last name.
Is possible to achieve using SQL? No need php nor anything.
Thanks in advance!
解决方案
选择 u.last_name , u.first_name , s.name,m.mark
来自用户 u ,主题 s ,标记 m
其中 u.user_id = m.user_id and s.subject_id = m.subject_id and s.course_id = m.course_id and s.course_id = 18 order by u.last_name asc
此查询仅适用于课程 ID 18,但您可以拥有所有课程 ID。
此查询不会产生您提到的格式的结果,但对于学生注册的每个科目,它将有一个单独的行。
希望这可能会有所帮助。
推荐阅读
- arrays - 使用 bash 在数组中旋转值
- javascript - fetch => response.json() 请求被拒绝
- r - 如何修复 R 中的“未定义列选择”错误?
- css - 更改输入自动完成框的颜色
- javascript - 如何通过 JavaScript document.querySelector 设置输入值
- swift - 如何搜索不认识的孩子
- c# - 使用 File.Exists 检查文件名是否存在 - 总是返回 false
- bash - “bash - apt-get”与此命令中的“apt-get”有何不同?
- django - 检索查询集的相关数据
- plsqldeveloper - 将新列添加到表时需要更改所有相关对象(简而言之)