Search code examples
mysqlsqldatabasegroup-byrelational-algebra

Equivalent of GroupBy and Having clause in Relational Algebra


I was doing an assignment where I had to convert SQL queries into Relational Algebra queries. I got stuck in converting the group by clause.

Could anyone please tell me how the group by clause can be written in relational algebra?

e.g.:

SELECT job, sal 
  FROM emp
 GROUP BY job
       ;

Thanks!


Solution

  • First of all your query is wrong you cannot select something that you did not group unless you use aggregation. I assume you want to get sum of the sal.

    job F sum(sal), job(emp).