List:General Discussion« Previous MessageNext Message »
From:Michael Widenius Date:April 14 1999 9:20pm
Subject:balances
View as plain text  
>>>>> "Michael" == Michael Farr <farrm@stripped>
> writes:

Michael> I would like to query a table with two columns, 1st being just a key field,
Michael> second being a debit field (float) ie

Michael> account:

Michael> service	|	debit
Michael> _______________________
Michael> 1		|	50
Michael> 2		|	100
Michael> 3		|	-30

Michael> I would like to query the table with a select and get back a balance field
Michael> calculated at run time as well ie

Michael> select debit, balance()
Michael> from account

Michael> debit		|	debit
Michael> _______________________
Michael> 50		|	50
Michael> 100		|	150
Michael> -30		|	120

Michael> Is this possible in MySQL?  I read that I may be able to say create
Michael> function balance() to create that function, but I don't know how to do that!

Michael> Any ideas would be muchly appreciated.

Hi!

Yes, you can do the above with an UDF function, but it will not work
if you use 'order by' on it!

Check the udf_example.c file and the MySQL documentation how to create 
udf functions.

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