我想要从表中选择后编号的数据行。问题是,我不需要顺序编号,但它应该从 1 到 3 编号,直到最后,如下所示:
1 | first row
2 | second row
3 | third row
1 | fourth row
2 | and
3 | ....
1
2
3
我正在尝试这个查询,但它不能正常工作:
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;
如何使其正常工作?