Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
199 views
in Technique[技术] by (71.8m points)

join - Relational Algebra "Only Once" or "Exists once"

So I have 2 relations

Student = {student id, name, address}
Course = {course no, title, subject}
Completed = {course no, student id, grade, semester}

and I want to display the name of students who have COMPLETED only one COURSE of "Physics" (Which is a subject)

I dont have problems joining the tables to get the data together, my problem is with how to get values that appear only once?

What I have so far

PICourse_no (σ Subject=′Physics′(COURSE))

That gets me all the course numbers that are Physics related

PIStudent_Id(σCourseNo= (PICourse_no (σ Subject=′Physics′(COURSE))))

And with that I think I'm getting the Id's of all the students who study a physics related course...but now here is my problem, how do I remove the students who have MORE than one physics related course?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

"how do I remove the students who have MORE than one physics related course?"

That is done by the relational MINUS operator or one of its nephews (sometimes known as antijoin). As indicated in the comments, there are a major number of distinct sets of operators all called "relational algebra". You really have to look into which one you are supposed to be using.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...