Doing a quick google on error ORA-00933 - it sounds like that shouldn't be thrown with a SELECT statement. Is there more to the query that you did not include in this post?
Either way, my process to troubleshoot such queries in SQL Server (not the same thing as Oracle, but the tricks should still work) would be to change your query to be less complex. For example, change it to a trivial SELECT TOP(1) without the DISTINCT or the WHERE (still need the group by as you are doing aggregates). Then see if that query succeeds. If so, increase the complexity. I personally would start by adding the WHERE clauses back in all at once leaving DISTINCT out and TOP in. If it fails, then one of your WHERE clauses has a typo. If it succeeds, put the DISTINCT back in.
Alternately, you could load up the terminal version of sql to connect to Oracle and it will highlight where you have a typo. I expect Toad has that too, but I do not have Toad installed and am not familiar with it.
My source - https://www.got-it.ai/solutions/sqlquerychat/sql-help/general-sql/ora-00933-sql-command-not-properly-ended-pl-sql/
The above is all just my opinion on what you should do.
As with all advice you find on a random internet forum - you shouldn't blindly follow it. Always test on a test server to see if there is negative side effects before making changes to live!
I recommend you NEVER run "random code" you found online on any system you care about UNLESS you understand and can verify the code OR you don't care if the code trashes your system.