このようなクエリがあります...
+-----+------------+--------+---------+---------+
| seq | fld_Date | CBU_IN | CBU_OUT | Balance |
+-----+------------+--------+---------+---------+
| 41 | 2012-10-08 | 150.00 | 0.00 | 150.00 |
| 42 | 2012-10-15 | 50.00 | 0.00 | 200.00 |
| 43 | 2012-10-22 | 50.00 | 0.00 | 250.00 |
| 44 | 2012-10-29 | 50.00 | 0.00 | 300.00 |
| 45 | 2012-11-05 | 50.00 | 0.00 | 350.00 |
| 46 | 2012-11-12 | 50.00 | 0.00 | 400.00 |
| 47 | 2012-11-19 | 50.00 | 0.00 | 450.00 |
+-----+------------+--------+---------+---------+
私が欲しかったのは、次の行の日付が fld_Date の次の行からのものであるこの種の出力だけです。
+-----+------------+---------------+--------+---------+---------+
| seq | fld_Date | next_row_date | CBU_IN | CBU_OUT | Balance |
+-----+------------+---------------+--------+---------+---------+
| 41 | 2012-10-08 | 2012-10-15 | 150.00 | 0.00 | 150.00 |
| 42 | 2012-10-15 | 2012-10-22 | 50.00 | 0.00 | 200.00 |
| 43 | 2012-10-22 | 2012-10-25 | 50.00 | 0.00 | 250.00 |
| 44 | 2012-10-25 | 2012-11-05 | 50.00 | 0.00 | 300.00 |
| 45 | 2012-11-05 | 2012-11-12 | 50.00 | 0.00 | 350.00 |
| 46 | 2012-11-12 | 2012-11-16 | 50.00 | 0.00 | 400.00 |
| 47 | 2012-11-16 | 2012-11-26 | 50.00 | 0.00 | 450.00 |
+-----+------------+---------------+--------+---------+---------+
これを手伝ってくれませんか...ありがとう...
これが私のクエリです...
SELECT
lms_savings.seq,
lms_savings.fld_Date,
FORMAT(lms_savings.CBU,2)AS CBU_IN,
FORMAT(lms_savings.CBU_OUT,2)AS CBU_OUT,
FORMAT(@Balance := @Balance + lms_savings.CBU - lms_savings.CBU_OUT,2) AS Balance
FROM lms_savings, (SELECT @Balance := 0) AS variableInit