Analytic Functions in SQL

 Analytic Functions in SQL


Analytic functions are used to perform calculations on groups of rows in a table. Unlike aggregate functions, analytic functions do not group the data and can return multiple rows for each input row. Here's an example:

sql


SELECT name, age, department, 

       AVG(age) OVER (PARTITION BY department) as avg_age

FROM employees;

In this example, we're using the AVG analytic function to calculate the average age for each department. The PARTITION BY clause is used to group the data by department.

No comments:

Post a Comment

The Importance of Cybersecurity in the Digital Age

 The Importance of Cybersecurity in the Digital Age Introduction: In today's digital age, where technology is deeply intertwined with ev...