Menu

Post image 1
Post image 2
1 / 2
0

Part 14: Window Functions (Ninja Mode)

DEV Community: sql·Mohamed Idris·3 days ago
#yjre6Avx
#dev#fullscreen#order#total#rank#article
Reading 0:00
15s threshold

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.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More