Produce a numbered list of members

Question

Produce a monotonically increasing numbered list of members (including guests), ordered by their date of joining. Remember that member IDs are not guaranteed to be sequential.

Expected Results

row_numberfirstnamesurname
1GUESTGUEST
2DarrenSmith
3TracySmith
4TimRownam
5JaniceJoplette
6GeraldButters
7BurtonTracy
8NancyDare
9TimBoothe
10PonderStibbons
11CharlesOwen
12DavidJones
13AnneBaker
14JemimaFarrell
15JackSmith
16FlorenceBader
17TimothyBaker
18DavidPinker
19MatthewGenting
20AnnaMackenzie
21JoanCoplin
22RamnareshSarwin
23DouglasJones
24HenriettaRumney
25DavidFarrell
26HenryWorthington-Smyth
27MillicentPurview
28HyacinthTupperware
29JohnHunt
30EricaCrumpet
31DarrenSmith

Your Answer

Your Results

Loading database...

Answers and Discussion

select row_number() over(order by joindate), firstname, surname
	from cd.members
order by joindate

This exercise is a simple bit of window function practise! You could just as easily use count(*) over(order by joindate) here, so don't worry if you used that instead.

In this query, we don't define a partition, meaning that the partition is the entire dataset. Since we define an order for the window function, for any given row the window is: start of the dataset -> current row.