元のクエリは次のとおりです.... next_row_date '2013-01-01' の日付が fld_date の最後のレコードではなく、next_row_date の最後のレコードが '2013-01-15' であることがわかる場合は、0 でなければなりません.
+-----+---+------------+---------------+ | | シーケンス | 私 | fld_Date | next_row_date | +-----+---+------------+---------------+ | | 41 | 1 | 2012-10-08 | 2012-10-15 | | | 42 | 2 | 2012-10-15 | 2012-10-22 | | | 43 | 3 | 2012-10-22 | 2012-10-29 | | | 44 | 4 | 2012-10-29 | 2012-11-05 | | | 45 | 5 | 2012-11-05 | 2012-11-12 | | | 46 | 6 | 2012-11-12 | 2012-11-19 | | | 47 | 7 | 2012-11-19 | 2013-01-01 | | | 49 | 8 | 2013-01-08 | 2013-01-15 | +-----+---+------------+---------------+
これが私が欲しかった出力です。このクエリで私を助けてもらえますか?
+-----+---+------------+---------------+ | | シーケンス | 私 | fld_Date | next_row_date | +-----+---+------------+---------------+ | | 41 | 1 | 2012-10-08 | 2012-10-15 | | | 42 | 2 | 2012-10-15 | 2012-10-22 | | | 43 | 3 | 2012-10-22 | 2012-10-29 | | | 44 | 4 | 2012-10-29 | 2012-11-05 | | | 45 | 5 | 2012-11-05 | 2012-11-12 | | | 46 | 6 | 2012-11-12 | 2012-11-19 | | | 47 | 7 | 2012-11-19 | 2013-01-08 | | | 49 | 8 | 2013-01-08 | 0 | +-----+---+------------+---------------+
SELECT
db_lms.a.seq,
(@i:=@i+1)AS i,
db_lms.a.fld_Date,
(db_lms.b.fld_Date)AS next_row_date
FROM db_lms.lms_savings a, db_lms.lms_savings b, (SELECT @i:=0) ii
WHERE (db_lms.a.seq = db_lms.b.seq-1) ORDER BY db_lms.a.seq ASC;