If software were better at error messages, something might have said, at any point in last 15 years, select customer, sum(orders.amount) as ltv left join orders on orders.customer_id = http://customer.id ) where ltv > 1000 <-- news you can use: you wanted to use HAVING here
-
-
Show this threadThanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
It’s awesome for filtering aggregated data. I remember the first time I found it and just sitting down for a few minutes marveling at new possibilities.
-
In retrospect the two years I spent working for Hell Boss after graduating from college were worth it: dude was an SQL genius and forced me to learn more of it than I would have otherwise been inclined to.
End of conversation
New conversation -
-
-
To generalize: learn SQL, not just your ORM. There is a lot of power in “thinking in sets”, let the db do the work of filtering and aggregating data. The SQL syntax doesn’t fit into the “class instance per db row” paradigm of ORMs. The key to using an ORM is knowing when to stop.
-
I was once called in to fix a performance problem with a big db. The “nightly report” was taking 14 hours to run. Turns out pulling millions of records across the network and summing them in Ruby can be slow. I rewrote the SQL to do the work in the db, then it took 20 min to run.
End of conversation
New conversation -
-
-
`having`, CTEs, `join lateral`, `filter (where)` window functions... databases have improved a lot in the past decade (Postgres in particular)
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
Did you know that SQL (at least postgres, Oracle and MS) supports recursion and is therefore Turing-complete?
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
You don’t even need HAVING to avoid temp tables, you can just filter on a sub-query: http://gphil.net/posts/2012-06-18-is-a-sql-having-clause-necessary.html …
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
I've made some serious performance gains on some complex systems (and some less complex ones) thanks to judicious use of HAVING and common table expressions.
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
That one was a game changer for me on the level of discovering cross apply/outer apply and CTEs.
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.