日期:2014-05-17  浏览次数:20966 次

求一个SQL,急!急!急!
有个A表:
no pk balance
1 aaaa 10
2 aaaa 20
3 aaaa 50
4 aaaa 70

要求写个SQL渔具实现一下查询结果
no pk balance before_balance
1 aaaa 10  
2 aaaa 20 10
3 aaaa 50 20
4 aaaa 70 50


速求啊 同志们 给力啊!!!!!!!!!!!


------解决方案--------------------
分析函数lag
------解决方案--------------------
select PK,balance ,lag(balance )over(order by PKde) as before_balance
from A ;
------解决方案--------------------
select no,pk,balance,lag(balance) over(order by balance)from A
------解决方案--------------------
SELECT NO,PK,BALANCE,LAG(BALANCE)OVER(ORDER BY NO) BEFORE_BALANCE
FROM A_TABLE;

------解决方案--------------------
http://blog.csdn.net/pilearn/article/details/6841764
详细说明
------解决方案--------------------
分析函数楼上的
------解决方案--------------------
SQL code
select pk balance lang(balance)over(order by pk) before_balance from A