Relational Algebra – Grouping with Multiple Attributes

group byrelational-theory

So I am having a bit of trouble understanding the Grouping operator, Ɣ.
If had a the relation Sales(employeeId, date, salePrice) and I wanted to list the largest salePrice for each employee per day, how would I group both by employeeId and date?

For example would it be
ƔemployeeId,date,MAX(salePrice)->largestSale(Sales)
or
ƔemployeeId,date; MAX(salePrice)->largestSale(Sales)
or something along those lines?

Best Answer

The usual notation is to write separately the grouping attributes from the aggregation functions, writing the attributes on the left of the γ symbol and the aggregation functions on the right, so your query should be something like this:

employeeId, date γ MAX(salePrice)→ largetSale(Sales)

This means:

  1. make a group for each different combination of employeeId and date in the Sales relation, and

  2. for each group produce a tuple with employeeId, date, maximum sale price of the group.