Is there a way in SQL to sequentially add a row number by key group?
Assume a table with arbitrary (CODE,NAME) tuples. Example table:
MySQL doesn't AFAIK. This covers most bases..
SELECT CODE, ROW_NUMBER() OVER (PARTITION BY CODE ORDER BY NAME) - 1 As C_NO, NAME FROM MyTable