MySQL Forums
Forum List  »  Newbie

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

A90-A92, A97-A99

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

Options: ReplyQuote

Written By
I want to write a user-defined Aggregate Function
September 06, 2012 01:10AM

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.