Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

9
  • 2
    Can you please provide a working fiddle - I tried with your DDL/DML above and got this... Also, it would probably be best if you included all of the query and relevant data - cf. (I removed parts of the query and columns that work the same way as others that I left in, for brevity. I'm sorry that there's still so much material but as mentioned, it's a complex query.)... Commented Jul 6, 2021 at 10:14
  • @Vérace You appeared to have skipped a couple tables from the creation script; the order I put them in should satisfy all constraints. The columns I removed from the query are still there in the tables I provided, I just don't select them in the query, but they aren't used in WHERE clauses or anywhere else anyway. I'll prepare a fiddle. Commented Jul 6, 2021 at 12:14
  • @Vérace I added a working dbfiddle to the question. However, the query is returning nothing there but I guarantee that on my database it does return some items. I'm not quite sure what could cause the difference. Commented Jul 6, 2021 at 12:26
  • Nevermind, I had forgotten the data for one of the tables, I'm so sorry. the fiddle is updated and works now. Commented Jul 6, 2021 at 12:32
  • 1
    Don't how much actual impact this makes, but one thing particularly stands out to me as redundant. The aggr derived table is cross-joined with the resl derived table, then the aggr columns are aggregated while the grouping is done by the resl columns. That makes little sense. Instead, you could aggregate the aggr rows separately, then cross-join the resulting single row with resl (obviously you wouldn't need to group anything at that point), see here. Commented Jul 14, 2021 at 12:17