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
In addition to the answer of @Janty here is a solution if you want to UDATE your table with the rownumber:
UPDATE myTable mt,(SELECT @curRow := 0, @curType := '') r SET type=
(
CASE type
WHEN @curType
THEN @curRow := @curRow + 1
ELSE @curRow := 1 AND @curType := type END
)
;
As janty too crewId is not within. Use a second "case" for that as mentioned in the other answers.