select sum(jfje),sum(dfje),sum(jkje) from 表名 where datediff(mi,rq,getdate())>1我没有调试过.

解决方案 »

  1.   

    SELECT rq, dw jfje, dfje, ye, CASE sign(total) 
          WHEN 1 THEN '借' WHEN 0 THEN '平' WHEN - 1 THEN '贷' END AS signflag
    FROM (SELECT rq, dw, jfje, dfje,
                      (SELECT SUM(jfje) - SUM(dfje)-SUM(jkje)
                     FROM tblcome
                     WHERE rq<= a.rq) AS total
            FROM tblcome a
            ) b但是数据量大时,性能较差.
      

  2.   

    update a set ye = (select sum(jfje) from table where dw = a.dw and rq < a.rq)
      - (select sum(dfje) from table where dw = a.dw and rq < a.rq)
      - (select sum(jkje) from table where dw = a.dw and rq < a.rq)
    from table a
      

  3.   

    declare @a money
    set @a=0
    update 表 set @a=@a+isnull(jfje,0)-isnull(dfje,0)-isnull(jkje,0),ye=@a
      

  4.   

    select rq, (select sum(jfje)+sum(dfje)+sum(jkje)  from 表名 where rq<a.rq) ye
    from table a
      

  5.   

    select rq, (select isnull(sum(jfje),0) - isnull(sum(dfje),0)- isnull(sum(jkje),0)  from 表名 where rq<a.rq) ye
    from table a
      

  6.   

    sorry 想用update 语句计算余额
      

  7.   

    select rq, dw,jfje,dfje,jkje,
         (select sum(jfje)-sum(dfje)-sum(jkje) from Tbl where rq<=a.rq) ye 
    from Tbl a