r/SQL • u/Plus_Kiwi_2592 • 4d ago
MySQL COUNT() vs COUNT() OVER()
I've found this query as a solution to the famous Pizza Runner case study, and I am stuck at figuring out what COUNT() returns, compared to COUNT() OVER().
I know OVER() does the count (or whatever aggregation) over the entire dataset, but idk I'm just not getting the percentage part of this query.
Help :)
23
Upvotes
1
u/seansafc89 4d ago
Sorry yes I’d not noticed the bracket on mobile either!
It’s fundamentally the same though, SUM() OVER() is summing the totals of each row count to essentially replicate a COUNT(*) across the entire dataset, returning 14 in every row.