Link to home
Start Free TrialLog in
Avatar of Basssque
Basssque

asked on

Exclude records that match or many instances of a value from an oracle query

Using the query below, is it possible to exclude all instances of a Student_Number if the total instances of 'F' in STOREDGRADES.GRADE is greater than 1?  Thanks so much!!

SELECT     
STUDENT_NUMBER,
LAST_NAME,
FIRST_NAME,
STOREDGRADES.STORECODE, 
SECTIONS.TERMID, 
STOREDGRADES.COURSE_NAME, 
STOREDGRADES.COURSE_NUMBER, 
SECTIONS.SECTION_NUMBER, 
STOREDGRADES.TEACHER_NAME, 
STOREDGRADES.GRADE,  
STUDENTS.GRADE_LEVEL

FROM         
PS.STOREDGRADES STOREDGRADES
LEFT JOIN PS.STUDENTS STUDENTS ON STOREDGRADES.STUDENTID = STUDENTS.ID 
LEFT JOIN PS.SECTIONS SECTIONS ON SECTIONS.ID = STOREDGRADES.SECTIONID
LEFT JOIN PS.COURSES COURSES ON STOREDGRADES.COURSE_NUMBER = COURSES.COURSE_NUMBER

WHERE     
(STOREDGRADES.TERMID >= 2500) 
AND (STOREDGRADES.TERMID <= 2599) 
AND (STOREDGRADES.STORECODE IN ('Y1')) 
AND (STUDENTS.SCHOOLID IN (61)) 
AND (STUDENTS.GRADE_LEVEL = 10)
AND (STUDENTS.ENROLL_STATUS = 0)
AND (STOREDGRADES.GRADE IS NOT NULL)

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Sean Stuber
Sean Stuber

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I'm not sure, but I suspect that student_name is not in the storedgrades table, so you may want to partition by storedgrades.student_id. (NO POINTS, PLEASE!)
Avatar of Sean Stuber
Sean Stuber

the partitioning clause doesn't require all of the columns to be in the same table.

my guess is student id and student number can probably be used interchangeably.

however, if they can't,  the described requirement is to count Fs by student number, so that is what should drive the partitioning clause.