I would like data rows numbered upon selecting from a table. Problem is that, I need not sequential numbering, but it should be numbered from 1 to 3 and so to the end, like below:
1 | first row
2 | second row
3 | third row
1 | fourth row
2 | and
3 | ....
1
2
3
I'm trying this query, but it does not work correctly:
mysql -> SET @n = 0;
-> SELECT
CASE
WHEN nnn = 3 THEN @n := 0
ELSE nnn
END
FROM (
SELECT @n := @n + 1 AS nnn FROM mytable
) AS t;
How to make it working correctly?