List:General Discussion« Previous MessageNext Message »
From:Colin McKinnon Date:April 14 1999 2:25pm
Subject:Re: balances
View as plain text  
At 20:05 14/04/99 +1000, Michael Farr wrote:
>I would like to query a table with two columns, 1st being just a key field,
>second being a debit field (float) ie
>
>account:
>
>service	|	debit
>_______________________
>1		|	50
>2		|	100
>3		|	-30
>
>I would like to query the table with a select and get back a balance field
>calculated at run time as well ie
>
>select debit, balance()
>from account
>
>debit		|	debit
>_______________________
>50		|	50
>100		|	150
>-30		|	120
>
>Is this possible in MySQL?  I read that I may be able to say create
>function balance() to create that function, but I don't know how to do that!
>
>Any ideas would be muchly appreciated.
>
>Thanks
>Mike

AIR It's just possible to do in *some* SQL dialects but it is an
EXCEEDINGLY difficult thing to do - the DBMS must have some sense of
sequence, which technically speaking, one based on a relational calculus
does not. In other words - I don't think it's feasible with MySQL which is
a very minimalist system (which is why I like it). Although it may be
possible to acheive on other systems, I don't think it's advisable.

Having said that, there's nothing to stop you accessing the data in a
different language and generating the figures for yourself, or developing a
tool to automatically maintain the data in the other column. I suppose you
could even write a MySQL function which retains some state from one row to
the next although you may then encounter some unexpected problems.

Colin

Thread
balancesMichael Farr14 Apr
  • Re: balancesColin McKinnon14 Apr
  • Re: balancesChristian Mack14 Apr
  • balancesMichael Widenius15 Apr