To add it to a straight SQL statement, you will need to join the recordset to itself as a subset using something called a heterogeneous join, and then roll the whole thing into an aggregate query to get a count of records that can be used for your ordinal values. It's not QUITE as complicated as it sounds, and we can post an example if you want to go this way.
The simpler method (and many times the more efficient approach) is to create your recordset in a stored procedure and insert it into a temporary table that has an incrementing identity value set. Then select from this temporary table to get your final output.
You SHOULD be doing your input/output/analysis through stored procedures anyway...
If it's not practically useful, then it's practically useless.