MySQL + SQL · Lesson 79

MySQL में Window Functions

Window Functions क्या हैं?

Window functions current row से related rows के set पर calculations करते हैं, उन्हें एक में collapse किए बिना (GROUP BY के उलट)। MySQL 8+ में उपलब्ध।

Example: Running Total

SELECT name, marks,
  RANK() OVER (ORDER BY marks DESC) AS rank_pos,
  AVG(marks) OVER () AS class_avg
FROM students;
हर row अपनी detail रखती है और साथ में rank व class average पाती है।

PARTITION BY

OVER (PARTITION BY class ORDER BY marks DESC) हर class के लिए calculation फिर से शुरू करता है — per-group windows की तरह।

सारांश

  • Window functions related rows पर compute करते हैं बिना collapse किए।
  • OVER() use करें; PARTITION BY per-group windows बनाता है।
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

💻 लाइव कोड एडिटर

इस पेज के प्रोग्राम यहीं तैयार हैं — चलाएँ, बदलें और सीखें। कुछ भी इंस्टॉल किए बिना।
OneCompiler द्वारा संचालित। कोड एडिटर में अपने आप आ जाता है — Run दबाकर आउटपुट देखें। अगर एडिटर न खुले तो नए टैब में खोलें.