'Algebra Relational sql GROUP BY SORT BY ORDER BY

I wanted to know what is the equivalent in GROUP BY, SORT BY and ORDER BY in algebra relational ?



Solution 1:[1]

You can use projection ? for the columns that you want group the table by them without aggregating (The PROJECT operation removes any duplicate tuples) as following:

? c1,c2,c3 (R)

where c1,c2,c3 are columns(attributes) and R is the table(the relation)

Solution 2:[2]

According to this SQL to relational algebra converter tool, we have:

SELECT agents.agent_code, agents.agent_name, SUM(orders.advance_amount)
FROM agents, orders
WHERE agents.agent_code = orders.agent_code
GROUP BY agents.agent_code, agents.agent_name
ORDER BY agents.agent_code

Written in functions sort of like:

? agents.agent_code
 ? agent_code, agent_name, SUM(advance_amount)
  ? agents.agent_code = orders.agent_code (agents × orders)

With a diagram like:

https://imgur.com/My9iV3D.png

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Prabhu
Solution 2 Lance