表ta 有如下内容:
pid    pcount
1      10
2      20
3      30
4      50写出sql语句,实现结果如下(后面记录的pcount值是前面所有pcount值的和:比如原纪录第一条pcount是10,第二天记录pcount是20 那么,结果就是第二条语句是10+20=30)pid   pcount
1     10
2     30
3     60
4     110

解决方案 »

  1.   


    可能我表达有误,是这样的原表的pcount值为10 20 30 50 那通过sql语句查出后就得是10 30 60 110
    其中结果的30就是原表的10+20 结果的60就是原表的10+20+30 结果的110就是原表的10+20+30+50
      

  2.   

    select pid,(select sum(pcount) from ta where pid <= a.pid)
    from ta a;
      

  3.   

    select pid,(select sum(pcount) from ta where pid <= a.pid) 
    from ta a; 
    这样的结果是不行的 我试了一下
      

  4.   

    哦 不会吧
    不会是你的 pid不是数字吧
      

  5.   

    噢,不知你用的什么数据库?我想我写的算是标准sql了mysql通过create table ta(pid integer, pcount integer);
    insert into ta values(1,10);
    insert into ta values(2,20);
    insert into ta values(3,30);
    insert into ta values(4,50);
    select * from ta;
    select pid,(select sum(pcount) from ta where pid <= a.pid) 
    from ta a;