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
>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()
>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.
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.