This is fairly easy to write from a table. It is hard to describe in abstract.
I usually have to use a subquery embedded in a subquery that identifies uniquely the first record for a given set. One query finds the minimum (say the earliest date, or smallest number) for a given group by element. The next one subquery finds the smallest id for that group by element. The row that matches that id is the first for that group by element. Any value in that row is the "First" for that group by element.
Russel Loski, MCSE Business Intelligence, Data Platform