Window function-এর খুব important concept।

Difference বুঝুন:

GROUP BY

Rows collapse করে।

PARTITION BY

Rows রাখে, কিন্তু group context দেয়।

Example

SELECT
    user_id,
    city,
    amount,

    AVG(amount) OVER (
        PARTITION BY city
    ) AS city_avg

FROM orders;

ধরুন 1,000 orders ছিল।

Output-এ এখনও:

1,000 rows

থাকবে।

প্রতিটা row-এর সাথে সেই city-এর average থাকবে।

GROUP BY করলে

1,000 orders
→ হয়তো 10 city rows

এটাই মূল difference।