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

Oracle DatabaseSQL

Avatar of undefined
Last Comment
Sean Stuber

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Sean Stuber

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
awking00

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!)
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.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes