Reputation: 75
I have three tables in MsAccess as follow:
Students(ID, Name, Class)
Subjects (ID, Name)
Marks (ID, StudentName[ID of Student], Subject.ID)
and following relation:
Marks.Subject = Subjects.ID
Marks.StudentID = Students.ID
I need to Display following output table:
--+--------------+---------------+--------------+--------------etc..
Student Name Subject1Name Subject2Name Subject1Name
--+--------------+---------------+--------------+--------------etc..
jkki LastN 15 50 30
XYZ LastN 25 60 70
gui LastN 05 30 50
Currently I have Follwing SQL:
Transform Marks.Obtained
SELECT Students.Name, Marks.Obtained
FROM (Students INNER JOIN (Marks INNER JOIN Subjects ON Marks.Subject = Subjects.ID)
ON Students.ID = Marks.StudentName)
GROUP BY Students.Name, Marks.Obtained
Pivot Subjects.Name
Which gives repeated output of the same name as follow:
--+--------------+---------------+--------------+--------------etc..
Student Name Subject1Name Subject2Name Subject1Name
--+--------------+---------------+--------------+--------------etc..
jkki LastN 15
jkki LastN 20
jkki LastN 05
Removing Group by Marks.Obtained from SQL gives following error: "you tried to execute a query that does not include the specified expression 'Obtained' as a part of aggregate function"
Please help me solve this problem.
Upvotes: 0
Views: 105
Reputation: 1269803
The Transform
should have an aggregation function. Try this:
Transform MAX(Marks.Obtained)
SELECT Students.Name
FROM (Students INNER JOIN
(Marks INNER JOIN
Subjects
ON Marks.Subject = Subjects.ID)
ON Students.ID = Marks.StudentName)
GROUP BY Students.Name
Pivot Subjects.Name
Upvotes: 1