I have a database with the following design
Standards:
ID | Standard | Mentor
1 | X | Mr. M
2 | IX | Mrs. S
Subjects:
ID | Subject | StandardID
1 | Adv. Math | 1
2 | Math | 2
3 | Eng | 2
Students:
ID | Name | StandardID
1 | A | 1
2 | b | 2
Marks :
ID | SubjectID | StudentID | Marks
1 | 1 | 1 | 10
2 | 2 | 2 | 9
3 | 3 | 2 | 8
Now I want to display the data as shown based on the standard
For X standard:
StudentID | Name | Adv. Math
1 | A | 10
For IX standard:
StudentID | Name | Math | Eng
2 | b | 9 | 8
Note :
- I am running sql server 2019
- Different standards have different number of subjects
- The number of subjects and their names per standard are unknown
- The number of standards are unknown
Is there any way to get the above results from a query? or do I need to change the table schema? If so then what needs to be changed to get the above results