I have a problem.The tool i work on does not accept subqueries. So i have to write a user defined custom aggregate function that does the following.
Example: col1 and col2 has numeric datatype.
**col1** **col2**
243 401
57489 400
2789 401
598 400
SELECT sum(MinValue)
FROM
(SELECT Min(col1) AS MinValue,col2
FROM
Table1
GROUP BY col2)
Output:841
I want this query to work in a single step by using a single function rather than as the query shown above. Something like:
SELECT MyMinSum(col1, col2),col3 from table1 Group by col3;
I hope it makes sense. I will appreciate any input on this.
If you are looking for same output what you are getting with your select statement using sub query, you could achieve the same result by
The best way is probably to put your SQL in a view, assuming that works with your tool.
But if you really need a custom aggregate function, there are two main ways to do it. The typical way is to use Oracle Data Cartridge Interface, such as the popular STRAGG. But in my experience, Data Cartridge is confusing, full of bugs, and slow. Usually the
COLLECT
function works much better. See the example below, or this SQL Fiddle.