12. 3. 2008 16:13
SET @rank = 0, @product = NULL; SELECT @rank := IF(@product = product, @rank + 1, 1) AS rank, @product := product FROM history ORDER BY product, id;