I want to produce query result base on this scenario that can create row number according to crew_id and type.
id crew_id amount type
1 4
@Janty's answer does not work when the type starts with a number (the rank starts at 2 instead of 1).
Use the following instead:
SELECT id,
crew_id,
amount,
CASE type
WHEN @curType THEN @curRow := @curRow + 1
ELSE @curRow := 1
END AS rank,
@curType := type AS type
FROM Table1 p
JOIN (SELECT @curRow := 0, @curType := '') r
ORDER BY crew_id, type