DBeaver is great for working with complex SQL queries (especially ones that use subqueries). You can break each subquery into tabs, work on them individually, analyze them, easily read the results in a visual spreadsheet, and even render a visual diagram of your database's schema so you can at-a-glance see how it's all connected.