これが私のテーブルです....
+----+--------+---------+------------+
| id | idName | fldName | fld_Date |
+----+--------+---------+------------+
| 1 | 1 | Marlon | 2013-06-03 |
| 2 | 1 | Marlon | 2013-06-05 |
| 3 | 1 | Marlon | 2013-06-07 |
| 4 | 1 | Marlon | 2013-06-08 |
| 5 | 1 | Marlon | 2013-06-11 |
| 6 | 2 | Dawn | 2013-06-03 |
| 7 | 2 | Dawn | 2013-06-06 |
| 8 | 2 | Dawn | 2013-06-08 |
| 9 | 2 | Dawn | 2013-06-11 |
| 10 | 2 | Dawn | 2013-06-15 |
| 11 | 3 | Jenny | 2013-06-15 |
| 12 | 3 | Jenny | 2013-06-19 |
| 13 | 3 | Jenny | 2013-06-14 |
| 14 | 3 | Jenny | 2013-06-21 |
+----+--------+---------+------------+
出力は次のようになります
+----+--------+---------+----+------------+------------+
| id | idName | fldName | i | fld_Date | next_date |
+----+--------+---------+----+------------+------------+
| 1 | 1 | Marlon | 1 | 2013-06-03 | 2013-06-05 |
| 2 | 1 | Marlon | 2 | 2013-06-05 | 2013-06-07 |
| 3 | 1 | Marlon | 3 | 2013-06-07 | 2013-06-08 |
| 4 | 1 | Marlon | 4 | 2013-06-08 | 2013-06-11 |
| 5 | 1 | Marlon | 5 | 2013-06-11 | 0 |
| 6 | 2 | Dawn | 1 | 2013-06-03 | 2013-06-06 |
| 7 | 2 | Dawn | 2 | 2013-06-06 | 2013-06-08 |
| 8 | 2 | Dawn | 3 | 2013-06-08 | 2013-06-11 |
| 9 | 2 | Dawn | 4 | 2013-06-11 | 2013-06-15 |
| 10 | 2 | Dawn | 5 | 2013-06-15 | 0 |
| 11 | 3 | Jenny | 1 | 2013-06-15 | 2013-06-19 |
| 12 | 3 | Jenny | 2 | 2013-06-19 | 2013-06-14 |
| 13 | 3 | Jenny | 3 | 2013-06-14 | 2013-06-21 |
| 14 | 3 | Jenny | 4 | 2013-06-21 | 0 |
+----+--------+---------+----+------------+------------+
ここに私のコードがあります...
SELECT id,idName,fldName, @i := @i + 1 i, fld_Date, next_date
FROM ( SELECT id,idName,fldName, @d next_date, @d := fld_Date fld_Date
FROM x_table,
(SELECT @d := 0) d ORDER BY id DESC) q,
(SELECT @i := 0) n ORDER BY id;
個別の数に基づいて増分を制限するのが難しいidName
...これらについて助けてもらえますか....