Create user-defined aggregates
This section describes how to create a user-defined aggregate and register it.
This section creates a simple aggregate that is called PenMax, which returns the second-largest value of the input set. If there is not a second-largest value, the aggregate returns NULL.