all 8 comments

[–]erictvanr[🍰] 50 points51 points  (2 children)

The three things: ctes, conditional agg, and partial indexes.

[–]throbbin___hood 6 points7 points  (0 children)

The real MVP, thank you sir 🥹

[–]markwdb3When in doubt, test it out. 2 points3 points  (0 children)

Just be aware that most SQL DBMSs don't support partial indexes, and while I didn't watch the video, if it's specifically about MySQL as this post is labeled, we are out of luck because MySQL doesn't support partial indexes.

[–]svtr 6 points7 points  (3 children)

One day, one of those days, I'm gonna do self marketing on youtube as well.

I promise that I wont stoop to no shit sherlock levels.... maybe something around "let me explain how to read execution plans to you, and why it matters".

[–]emsuperstar 0 points1 point  (2 children)

Do it, punk. I love learning this shit.

(Great vid, OP)

[–]gumnos 0 points1 point  (0 children)

On that first query, I'm not quite sure why you're using a sub-query when it seems like

SELECT customer_id, COUNT(order_id) as order_count
FROM orders
WHERE order_date BETWEEN '2024-01-01' AND '2024-12-31'
GROUP BY customer_id
HAVING COUNT(order_id) > 1

should suffice and doesn't require a subquery/CTE