I need at select rows from table, make numbering rows so: first 3 rows numbering as:
1 2 3
and after ( from the fourth row ), start numbering again and this second numbering continue to the end of all records, that is result must be like this:
1 2 3 1 2 3 4 5 .... .... 777
I write this query, but this returns usual numbering, from 1 to last record.
Please, someone tell me, where have I logical wrong in my query? In my opinion, this will returns numbring, as I write above
mysql-> SET @n = 0
mysql-> SET @start_again = 'true'
SELECT
CASE
WHEN @n = 3 AND @start_again = 'true' THEN @n := 1
ELSE @n := @n + 1
END,
CASE
WHEN @n = 3 AND @start_again = 'true' THEN @start_again := 'false'
END
FROM mytable