要是用sql不好实现的话就自己写一个存储过程吧

解决方案 »

  1.   

    楼主,一个SQl语句可能解决不了问题吧.
    提供建议
    1.如果你的数据库支持写过程.  就自己写过程自己处理
    2.当然也可以在应用程序中处理
      

  2.   

    select name a,(select sum(pay) from sumTest where name=a.name and month<a.month) sumO from sumTest a
      

  3.   

    对了,null值用ISNULL()替换
    select name ,ISNULL((select sum(pay) from sumTest where name=a.name and month<a.month),0) sumO from sumTest a
      

  4.   

    select name,(select isnull(sum(pay),0) as pay from test where name=a.name and month<a.month) sumO from test a