MySQL Forums :: Newbie :: I want to write a user-defined Aggregate Function


Advanced Search

I want to write a user-defined Aggregate Function
Posted by: Adnan Raza ()
Date: September 06, 2012 01:10AM

I want to write a custom aggregate function in mySQL just like min or max. What I want to do is to take an array as an argument in a function which will process it and return a single value.

For instance, If we have a table with data as below.
tbl
ID | NAME | Serial
1 | A | A90
2 | A | A91
3 | A | A92
4 | A | A97
5 | A | A98
6 | A | A99

and we want to use a query that groups it by using "group by"
select min(Serial) as starting_nbr, min(Serial) as ending_nbr
from tbl
group by NAME;

the result would be
starting_nbr | ending_nbr
A90 | A99


but I want following output, which is probably not possible by using min and max functions.

Output
A90-A92, A97-A99

To achieve above output, I need to write an aggregate function or any other solution, if possible.

Options: ReplyQuote


Subject Written By Posted
I want to write a user-defined Aggregate Function Adnan Raza 09/06/2012 01:10AM
Re: I want to write a user-defined Aggregate Function laptop alias 09/06/2012 04:10AM
Re: I want to write a user-defined Aggregate Function Adnan Raza 09/06/2012 05:41AM
Re: I want to write a user-defined Aggregate Function laptop alias 09/06/2012 07:00AM
Re: I want to write a user-defined Aggregate Function Adnan Raza 09/06/2012 10:54PM
Re: I want to write a user-defined Aggregate Function laptop alias 09/11/2012 07:58AM
Re: I want to write a user-defined Aggregate Function Adnan Raza 09/11/2012 10:23PM
Re: I want to write a user-defined Aggregate Function laptop alias 09/07/2012 01:02AM
Re: I want to write a user-defined Aggregate Function Adnan Raza 09/07/2012 01:24AM
Re: I want to write a user-defined Aggregate Function Rick James 09/08/2012 05:39PM
Re: I want to write a user-defined Aggregate Function Adnan Raza 09/10/2012 07:24AM
Re: I want to write a user-defined Aggregate Function laptop alias 09/10/2012 07:31AM
Re: I want to write a user-defined Aggregate Function Adnan Raza 09/10/2012 07:57AM
Re: I want to write a user-defined Aggregate Function Rick James 09/10/2012 08:01AM
Re: I want to write a user-defined Aggregate Function Adnan Raza 09/10/2012 08:11AM
Re: I want to write a user-defined Aggregate Function Adnan Raza 09/10/2012 08:57AM
Re: I want to write a user-defined Aggregate Function laptop alias 09/10/2012 10:26AM
Re: I want to write a user-defined Aggregate Function Adnan Raza 09/11/2012 01:29AM
Re: I want to write a user-defined Aggregate Function Rick James 09/11/2012 08:10AM
Re: I want to write a user-defined Aggregate Function Adnan Raza 09/11/2012 10:21PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.