Can I get a copy?
Discussion
A few random thoughts on query performance…
- Know the SQL order of operations, do any filtering as early as possible in that flow.
- Use your DB’s built-in functions instead of writing that logic by hand, including window functions.
- Don’t layer views on views on views (same applies to many nested sub-queries).
- Unless your application DB has a very simple schema, you should consider some additional data modeling to serve any type of analytics use case.