code_junkie

mysql stored procedure question

Nov 12th, 2011
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. SET @balance := 0;
  2. SET @high := 0;
  3. SELECT @high := GREATEST(@balance := @balance+credit-debit, @high) FROM mytable;
  4. SELECT @high;
  5.  
  6. CREATE FUNCTION high_bal() RETURNS DECIMAL
  7. BEGIN
  8. SET @balance := 0;
  9. SET @high := 0;
  10.  
  11. SELECT MAX(@high := GREATEST(@balance := @balance+debit_acc-credit_acc, @high))
  12. INTO @high
  13. FROM credit_acc where credit_used_acc=63395;
  14.  
  15. RETURN @high;
  16. END$$
  17.  
  18. BEGIN
  19. SET @balance := 0;
  20. SET @high := 0;
  21. SELECT @high := GREATEST(@balance := @balance+debit_acc-credit_acc, @high) FROM credit_acc where credit_used_acc=63395;
  22.  
  23. RETURN @high;
  24. END$$
  25.  
  26. print("code sample");
  27.  
  28. DELIMITER ;
  29.  
  30. select max(debit-credit) from yourtable
Add Comment
Please, Sign In to add comment