This post is part of the SQL: Zero to Ninja series. Your boss asks: "Show me each user's orders, and next to every order put its rank, like their 1st order, 2nd order, 3rd, by total." You reach for GROUP BY ... and hit a wall. GROUP BY squashes all of a user's orders into one row. But you wanted to keep every order AND add a rank. You need both. That is exactly what window functions do, and they are the move that turns you into a SQL ninja. The idea in one line A window function computes a value across a group of rows (a "window") while keeping every single row , unlike GROUP BY , which collapses them into one. The metaphor: the bakery queue You are standing in line at the bakery. A little screen says you are customer number 4 . You can see your position in the line. But here is the thing: you are still you , still standing there as yourself. You did not get blended into "the line." You kept your identity and also got a number. That is a window function.…