So I have a table similar to this one. Each user has posted a review about one or more hotels(A,B,C,D) but on different dates so there are no duplicate tuples even though a person might have reviewed the same hotel more than once.
I need to count the number of DISTINCT hotels every user has reviewed using RELATIONAL ALGEBRA only. How can I do that?
example to show notations I use:
R = ƔUser,COUNT(Hotel_reviewed)->Num_Reviews (InitialRelation- table 1)
would give the number of reviews by each user
The result should be the following table:
example to show notations I use:
R = ƔUser,COUNT(Hotel_reviewed)->Num_Reviews (InitialRelation- table 1)
would give the number of reviews by each user
Best Answer
Besides the more compact syntax (from @McNets' answer):
we can also do a projection first to find distinct User, Hotel_Reviewed pairs and then aggregate:
This leads us to the relational algebra notation: