There are many variants and extensions of relational algebra described in books. I assume that you have a group by operator, which is an extension of the classical relational algebra, and it is written as:
a1... an γ f1...fm
where each ai is a grouping attribute, and fi is an aggregation function.
Using this operator, your query could be answered by the ...
I would do something like the following (see the fiddle here):
Create and populate a table:
CREATE TABLE test
key INTEGER NOT NULL,
value INTEGER NOT NULL
INSERT INTO test VALUES
(1, 5), (2, 6), (2, 7), (2, 8), (4, 9);
SELECT * FROM test;