From: Michael Widenius Date: April 14 1999 9:20pm Subject: balances List-Archive: http://lists.mysql.com/mysql/1856 Message-Id: <14101.1555.459348.995893@monty.pp.sci.fi> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit >>>>> "Michael" == Michael Farr 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