We have the following schema:

instructor(ID, name, dept name, salary)
teaches(ID, course id, sec id, semester, year)

Find instructors who taught the most courses in 2009. Can someone please help me? I'm confused how to write this out in relational algebra.

有帮助吗?

解决方案

This must be homework ;-) So I'll give you some hints...

Since I haven't done tuple relational calculus since college (http://en.wikipedia.org/wiki/Relational_algebra), here is an approximation in sql,

select instructor.ID, instructor.name, count(teaches.ID)
from instructor
join teaches on teaches.ID = instructor.ID
and count(teaches.ID) >= ...
group by ...

Leaving you to fill in the group by and >= values.

Think about how you calculate how many courses each teacher teaches,

select teaches.ID, count(*)
from teaches
group by teaches.ID

This might help: MySQL count maximum number of rows

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top