-1

Click here to view image

Please see the attached picture. There are two title(test) that each grade must take, for example Alg1 PMT1 2016-17 and Alg1 PMT2 2016-17. I would to display the results for each test_id side by side based on the staff_id. I tried to use self joins, but I am getting duplicates. Please Help

Joe
  • 32
  • 9
  • 2
    First, there Is no picture posted. Second, try this: http://stackoverflow.com/questions/17959279/how-to-prevent-duplicates-with-inner-join-query-postgres – arias_JC Jan 31 '17 at 17:05
  • Sorry this is my first post on stackoverflow. Here the link to the picture: https://i.stack.imgur.com/kQhLV.jpg – Joe Jan 31 '17 at 17:12
  • http://meta.stackoverflow.com/questions/285551/why-may-i-not-upload-images-of-code-on-so-when-asking-a-question/285557#285557 –  Feb 22 '17 at 14:42

2 Answers2

1

I assume you found your answer using distinct

arias_JC
  • 549
  • 3
  • 15
0

I figured it out. I used the min and max function to isolate the IDs.

select distinct  x.School, x.grade, x.Teacher, x.test as Test1, x.title as Course_name, x.short_name as Course_number, x.course_period_id,  x.Students as Student, x.Number_Correct, x.Possible_Points, x.Percent_Correct,y.test as test2, y.course_period_id as course_period_id2,y.Students as Student2,y.Number_Correct as correct2, y.Possible_Points as Possible_Points2, y.Percent_Correct as Percent_Correct2, round((y.Percent_Correct)-(x.Percent_Correct)) as Grouth from final x

inner join(select distinct  School, grade, Teacher, test_id, test, short_name, Class_id, course_period_id, Students, Number_Correct, Possible_Points, Percent_Correct from final where (select max(test_id) from final) = test_id) y on ( x.course_period_id=y.course_period_id and x.grade = y.grade)
where (select MIN(test_id) from final ) = x.test_id
order by x.School,X.Teacher,x.grade,  x.course_period_id
Joe
  • 32
  • 9