retrieve correct data from my schemas

落爺英雄遲暮 提交于 2019-12-17 16:41:53

问题


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)?


回答1:


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.



来源:https://stackoverflow.com/questions/41797228/retrieve-correct-data-from-my-schemas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!