Relational Database - Finding instructors who taught the most courses in 2009

StackOverflow https://stackoverflow.com/questions/19418298

  •  01-07-2022
  •  | 
  •  

Question

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.

Était-ce utile?

La solution

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top