What is a window function in SQL?

Quality Thought – Best Data Science Training Institute in Hyderabad with Live Internship Program

If you're aspiring to become a skilled Data Scientist and build a successful career in the field of analytics and AI, look no further than Quality Thought – the best Data Science training institute in Hyderabad offering a career-focused curriculum along with a live internship program.

At Quality Thought, our Data Science course is designed by industry experts and covers the entire data lifecycle. The training includes:

Python Programming for Data Science

Statistics & Probability

Data Wrangling & Data Visualization

Machine Learning Algorithms

Deep Learning with TensorFlow and Keras

NLP, AI, and Big Data Tools

SQL, Excel, Power BI & Tableau

What makes us truly stand out is our Live Internship Program, where students apply their skills on real-time datasets and industry projects. This hands-on experience allows learners to build a strong project portfolio, understand real-world challenges, and become job-ready.

Why Choose Quality Thought?

✅ Industry-expert trainers with real-time experience

✅ Hands-on training with real-world datasets

✅ Internship with live projects & mentorship

✅ Resume preparation, mock interviews & placement assistance

✅ 100% placement support with top MNCs and startups

Whether you're a fresher, graduate, working professional, or career switcher, Quality Thought provides the perfect platform to master Data Science and enter the world of AI and analytics.

📍 Located in Hyderabad | 📞 Call now to book your free demo session and take the first step toward a data-driven future!.

A window function in SQL performs calculations across a set of rows that are related to the current row, without collapsing them into a single result (unlike GROUP BY). It is evaluated using an OVER() clause that defines the “window” (range of rows) for the calculation.

🔑 Key Points about Window Functions

  1. Operate on a set of rows but return a value for each row.

  2. Do not reduce the result set like aggregates (SUM, AVG with GROUP BY).

  3. Require the OVER() clause, which can include:

    • PARTITION BY → Divides rows into groups (like GROUP BY).

    • ORDER BY → Defines order of rows for calculations.

🔑 Common Window Functions

  1. Ranking Functions

    • ROW_NUMBER() → Assigns unique numbers to rows.

    • RANK() → Ranks rows, leaving gaps on ties.

    • DENSE_RANK() → Ranks rows without gaps.

    SELECT name, salary, RANK() OVER (ORDER BY salary DESC) AS rank FROM employees;
  2. Aggregate Functions

    • SUM(), AVG(), COUNT(), MIN(), MAX()

    • Work across a partition but keep all rows.

    SELECT department, salary, AVG(salary) OVER (PARTITION BY department) AS avg_salary FROM employees;
  3. Value Functions

    • LEAD() → Fetches next row’s value.

    • LAG() → Fetches previous row’s value.

    • FIRST_VALUE(), LAST_VALUE() → Return first/last value in the window.

    SELECT name, salary, LAG(salary) OVER (ORDER BY salary) AS prev_salary FROM employees;

⚡ Summary

  • A window function applies aggregate-like calculations per row, based on a defined window of rows.

  • Unlike GROUP BY, it keeps individual rows visible.

  • Useful for analytics: running totals, rankings, comparisons, moving averages.

👉 In short: Window functions = Aggregates + Per-row context.

Read More :


What is the difference between INNER JOIN and LEFT JOIN?

Visit  Quality Thought Training Institute in Hyderabad     

Comments

Popular posts from this blog

What is a primary key and foreign key?

What is label encoding?

What is normalization in databases?