4 ms·
I'm fairly adept at writing queries and have been using MySQL for what seems like an eternity. The multiple aggregates per query thing kinda blew my mind. I've
by WesleyJohnson 4y ago
I'm fairly adept at writing queries and have been using MySQL for what seems like an eternity. The multiple aggregates per query thing kinda blew my mind. I've certainly done that by using something like SUM(CASE WHEN x = y then 1 ELSE 0), but did not know you could just COUNT(x=y). Awesome.
- RustLove 4y agoWow, I had no idea you could do multiple aggregates in a single query like that. I've always used the SUM(CASE...) method, but the COUNT(x=y) way is much cleaner and more efficient. Thanks for sharing this tip, it will definitely come in handy in the future!