I need some help. I want to display All scores from students, If the score has been input to db, it will display the score, if not it will display null value.
Database structure like this :
students
- nim
- name
- class_year (like : 2020, 2021, etc)
krs - code_krs
- nim
- academic_year (like : 20201, 20202, etc)
- total_sks
krs_detail - id
- code_krs
- course_code
- sks
courses - course_code
- course_name
- sks
scores - academic_year (like : 20201, 20202, etc)
- course_code
- nim
- score
I try query like this : `
SELECT students.nim, students.name, krs_detail.course_code, courses.course_name, courses.sks, scores.score
FROM students
JOIN scores ON scores.nim = students.nim
RIGHT JOIN courses ON courses.course_code = scores.course
JOIN krs_detail ON krs_detail.course_code = courses.course_code
WHERE krs_detail.code_krs = '1411503293-20222';
Data displayed is correct, with nim & name student : enter image description here
But, if i change krs_detail.code_krs with other data, example 2161206003-20211, data displayed is wrong :
enter image description here
All data score should be null/empty, because score has not been insert to db, nim displayed : 2161206003, name : Farhan.
Thanks for your help
1条答案
按热度按时间iibxawm41#
My interpretation is that
students
andcourses
.krs
andkrs_detail
scores
table.If so, the data model looks like below:
The score report needs to display
course code
,course name
andsks
.If the above is correct, the granularity of the dataset is (
nim
,academic_year
,course_code
)We can
scores
to retrievescore
.An example of result: