How to add virtual column in relational algebra

348 Views Asked by At

Suppose we have table A and a table B which has foreign key referencing to A's PK.

I used to perform the following query in SQL (MySQL to be exact) to select all rows and columns of A and an aggregation (for example SUM) of Bs for each row of A.

SELECT A.*, 
       (
           SELECT SUM(B.value)
           from B
           WHERE B.AID = A.ID
           ) AS sum_b,
FROM A;

I wonder how can I add this virtual columns in relational algebra. Does the projection operator can accept a relation as its argument? If yes how would be the notation?

0

There are 0 best solutions below