Вопрос

A very simple question about relational algebra that I cannot find any answer in internet or/and some books.

Suppose the relation employee(key,salary,bonus), and I want to create a new relation R(key,totalMoney) where totalMoney = salary + bonus. My try is:

R1(key,totalMoney) = projection key,salary (employee)

R2(key,totalMoney) = projection key,bonus (employee)

R = key aggregate sum totalMoney (R1 U R2)

Is it ok?

If it is ok, however, it is not resolve all my problems :(

Suppose I now want to get RT2(key, totalMoney * 2). For this, my attempt is:

RT2 = update totalMoney <- totalMoney*2 (R) //"update" is a relational algebra operator

Is it ok?

I think my answers are not (very) good. If you can help me to find a nice and neat solution, I will appreciate.

Thanks

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

Решение

Codd's original algebra did not include such an operation because he firmly believed that such computations should be done in the application.

And alas most of what is being taught these days is still very close to these original ideas of Codd's. Which are 40 years old by now. And so all the evolutions that have taken place during those 40 years are, alas, mostly overlooked.

One of those things is the EXTEND operator that was introduced, somewhere along the line, by Chris Date & Hugh Darwen I believe. This operator takes care of exactly what you need.

Другие советы

Traditional relational algebra does not support arithmetic operations. However, different attempts have been made to extend it: for instance Gabbay and McBrian discuss arithmetic extensions of selection and projection operators, while Boncz et al. have proposed a number of relational algebra extensions (including arithmetic operations) for their XQuery compiler Pathfinder.

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