Вопрос

I have this question.

for two table : first, is employee : Employee(id, roomID) and second is : Room(roomID, roomName)

The question is : How many employees work in each room.

I can do this easily in SQL Language :

select Room.roomID, COUNT(Employee.id) as NumofEmployee
from Employee, Room
where employee.roomID = Room.roomID
group by Room.roomID

The same question, but writing under Relational Algebra language. This question makes me headache so much, because I know in this language, just have some simple operation : join selection projection difference. So, many SQL command I don't know how to do with, for example : group by or count.

Thanks :)

Это было полезно?

Решение

Aggregation and grouping operations can't be constructed from the basic relational algebra operations. You would have to define your own COUNT and GROUP BY operators to perform this.

There are many proposed extensions to the basic relational algebra that you could use, or you could even define your own - but to do this formally, I suspect the mathematics would get reasonably complex.

A simple proposal (without much formality) can be found here, http://myweb.lmu.edu/dondi/share/db/relational3.pdf. (Section 3.2)

Using the extended algebra proposed in that link, your expression would be written like:

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top