Wrap group_by sql with a subquery for limiting rows in Oracle.

Fixes #128

Rebase of #129