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
299 views
in Technique[技术] by (71.8m points)

relational database - retrieve correct data from my schemas

enter image description here

I would like to retrieve the Names of teachers who teach more than 1 course

I am really stuck on how to do it , all I know is that I need to consider the Course schema and operate on it , could I get some advice in terms of pi(projection),sigma(condition),rho(rename) etc (not i any specific database language)?

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

Since this is homework and you basically need to read & work through a textbook's absolutely introductory text & exercises on relational model basics & the relational algebra, I give some guiding questions tailored to your assignment.

A relation (given or query result) comes with a predicate, ie a statement template parameterized by attributes. A relation holds the tuples that make a true statement from its predicate. PKs & FKs are not needed for querying.

What is a relation expression for the tuples where...

the person identified by teacherid teaches the course identified by cid, which is named name? (Answer: Course.)
teacherid teaches cid named name? (Same answer. Why?)
teacherid teaches cid AND cid is named name? (Same answer. Why?)

(We can infer from your assignment query that the Course & Teacher predicates refer to persons or you couldn't get at teacher names.)

t teaches c named n?
t teaches c named n AND c = 101?
t teaches c named n AND t occupies o?

t teaches some course named some name?
for some c, t teaches c named some name? (Same answer. Why?)
for some c, t teaches c named something AND c = 101? (Why do we need FOR SOME?)

i ids a student AND NOT i takes some course taught by some teacher?
some student takes some course taught by t OR t occupies some office?

Thus: We compose a query predicate for the tuples we want using logic operators and the given predicates. Then we get an expression that calculates them by converting logic operators to relation operators and given predicates to given relations. (It can be tedious rearranging to get two relations with the same attributes in order to use AND NOT (MINUS) or OR (UNION).)

See this.

retrieve the Names of teachers who teach more than 1 course

You want tuples where attribute Name is the name of a person and for some two values the person teaches the first one's course and they teach the second one's course and those values/courses are not the same.


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

...