a4bd55725b
This refactors the SQL to join on a distinct list of users, removing the need for GROUP BY statements, and fixing the related errors in Oracle/MSSQL