PHP MYSQL SUM Until a row then stop -
basically creating sort of checking account type query. easy except want split pages.
so have field called amount , can positive or negative number.
the problem if on records 75-100 need have query sum of amount until record 75 , give me total. can run query records 75-100 , loop through amounts so: (supposing sum , including 74 $500)
record# amount total 75 25.00 525.00 76 35.00 560.00 77 40.00 600.00 etc. what thinking idnum record 75 , sum until finds so: sum(case when idnum != $until amount else 0 end)
however keeps going. doesn't stop @ 75 skips 75 sums 76, 77, etc.. appreciated.
set @total=0; select recordno, amount, @total:= @total+ amount total table1 limit 75, 75 or
select cur.id, cur.amount, sum(prev.amount) table1 cur left join table1 prev on cur.id >= prev.id group cur.id limit 75, 75 here limit function start records 76 75 records, can send parameter
Comments
Post a Comment