-1

I have query like this one...

+-----+------------+--------+---------+---------+
| 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  |
+-----+------------+--------+---------+---------+

all I wanted is this kind of output where in the next row date are from the next row of 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  |
+-----+------------+---------------+--------+---------+---------+

Can you help me with this one... Thanks...

here's my query...

 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
4

2 回答 2

0

将您的查询替换为“您的查询”

 select a.seq, a.fld_Date,b.fld_Date as next_row_date, 
        a.CBU_IN,a.CBU_OUT,a.Balance 
 from ( your query ) a left outer join (your query) b
 on a.seq = b.seq-1
于 2013-06-26T06:33:41.923 回答
0
select a.seq, a.fld_Date, b.fld_Date as next_row_date , a.CBU_IN, a.CBU_OUT, a.Balance   
from table_name a, table_name b
where a.seq = b.seq+1
于 2013-06-26T06:38:25.497 回答