Numbering a rows positional index relative to its siblings within a parent context So, I have a table that contains numerous entries of text, but each one has a parent context that identifies the entries within a group, such as:

+------+-------+------+
| PKID | GrpID | Body |
+------+-------+------+
| 1    | 1     | a... |
+------+-------+------+
| 2    | 2     | b... |
+------+-------+------+
| 3    | 2     | c... |
+------+-------+------+
| 4    | 1     | d... |
+------+-------+------+
| 5    | 3     | e... |
+------+-------+------+
| 6    | 3     | f... |
+------+-------+------+
| 7    | 2     | g... |
+------+-------+------+
| 8    | 1     | h... |
+------+-------+------+
| 9    | 1     | i... |
+------+-------+------+


Now, I am trying to get a numeric value (calculated based on the rows position within the result, so it could be different each time based on what predicates are used) for the position of each row. So (I have ordered it by GrpID to make it easier to read, but imagine it was ordered naturally):

+------+-----+-------+------+
| PKID | Idx | GrpID | Body |
+------+-----+-------+------+
| 1    | 1   | 1     | a... |
+------+-----+-------+------+
| 4    | 2   | 1     | d... |
+------+-----+-------+------+
| 8    | 3   | 1     | h... |
+------+-----+-------+------+
| 9    | 4   | 1     | i... |
+------+-----+-------+------+
| 2    | 1   | 2     | b... |
+------+-----+-------+------+
| 3    | 2   | 2     | c... |
+------+-----+-------+------+
| 7    | 3   | 2     | g... |
+------+-----+-------+------+
| 5    | 1   | 3     | e... |
+------+-----+-------+------+
| 6    | 2   | 3     | f... |
+------+-----+-------+------+


What query could be performed on such a dataset that would give me such a result?
In SQL Server and other systems that support ROW_NUMBER...

SELECT *,
    ROW_NUMBER() OVER (
        PARTITION BY GrpID
        ORDER BY PKID
    ) AS Idx
FROM YourTable;